由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - find treenode with two indegrees
相关主题
问道题,binary tree里有一个有indegree 2回馈本版,新鲜店面,新题新气象
今天面的太惨了....热腾腾的 LinkedIn 电面题攒RP
贡献Google 电面面经一道google面试题
几道FG的面试题请教个G题目
一道在线题请教这么一个题:BST maximum sum path
G棉经Uni_value subtree problem
Zenefits 面经 OA+Skype+onsitecareercup 150 4.1 balanced tree 有错?
Amazon 打印给定node距离最近的K个nodes查找binary tree中有多少个uni-valued subtree
相关话题的讨论汇总
话题: node话题: tree话题: indegree话题: cycle话题: right
进入JobHunting版参与讨论
1 (共1页)
k***t
发帖数: 276
1
看到一个题和一个答案。不太理解。
1.What does it mean that "tree representation is in Linked list format"?
Is there a standard way to represent a tree with a linked list? Or does it
just refer to the fact that TreeNode has left and right child link/pointers.
2. "When we thread a binary tree while doing preorder traversal, it wont
result in any cycle."
Is there a standard way to "thread' a binary tree? There is no "cycle"
concept at all in normal tree traversal, isn't it?
=======================================
Suppose there is a binary tree having millions of nodes and by mistake one
node has two indegree........(i.e. There becomes a cycle/loop in that tree .
..u have to find that node which is having two indegree....
Constraint is no extra memory can be used and tree representation is in
Linked list format...
for example..
............0
........../..\
.........1...2
......../.\./.\
.......3...4...5
....../.\...\
.....6...7...8
node 4 is having two indegree....we have to find that node....
===============================================================
When we thread a binary tree while doing preorder traversal, it wont result
in any cycle. But it leads to a cycle in this case. We can make use of this
fact.
preorder:
i) Print node.
ii) If node->left is not NULL search right most node in the left subtree of
the current node and make the current nodes right child as the right child
of the found node.
iii) If node->left is NULL, go to the right subtree, ie current node=
current node->right.
This will yield a acyclic directed graph in an ideal case, but a cyclic
graph in case the indegree of any node is > 1.
1 (共1页)
进入JobHunting版参与讨论
相关主题
查找binary tree中有多少个uni-valued subtree一道在线题
树中序遍历,要求左子树用递归,右子树用iterationG棉经
微软面试的一道题Zenefits 面经 OA+Skype+onsite
A家,link all node in the same levAmazon 打印给定node距离最近的K个nodes
问道题,binary tree里有一个有indegree 2回馈本版,新鲜店面,新题新气象
今天面的太惨了....热腾腾的 LinkedIn 电面题攒RP
贡献Google 电面面经一道google面试题
几道FG的面试题请教个G题目
相关话题的讨论汇总
话题: node话题: tree话题: indegree话题: cycle话题: right