由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Depth-First-Search
相关主题
这个题目有什么trick求问一题G家的面经
请教一道面试题图的拷贝
BFS traverse O(1) space?这个check whether a binary tree is a BST 问题
Graph DFS Iterative题目: iterative binary tree post order traversal
问一个graph题DFS用stack不用递归的话怎么color node?
F家电面从tree的post order traversal和pre,能否build这个tree?
print bst in level order dfs为什么是O(N)不应该是O(N^2)吗?MS onsite 面经
请叫大家一道题G家电面面经--佛云了~~
相关话题的讨论汇总
话题: order话题: dfs话题: stack话题: node话题: each
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
In the following graph, with starting point 0, what is the order of DFS
traversal?
0
/ \
1 2
/
3
We use a stack for DFS visit. The problem is, is the visit order the order each node is pushed into the stack, or the order each node is popped from the stack.
q****x
发帖数: 7404
2
dfs is post-order.

each node is pushed into the stack, or the order each node is popped from
the stack.

【在 c**********e 的大作中提到】
: In the following graph, with starting point 0, what is the order of DFS
: traversal?
: 0
: / \
: 1 2
: /
: 3
: We use a stack for DFS visit. The problem is, is the visit order the order each node is pushed into the stack, or the order each node is popped from the stack.

c**********e
发帖数: 2007
3
Are you sure? A professor says the answer is 0213 or 0132.

【在 q****x 的大作中提到】
: dfs is post-order.
:
: each node is pushed into the stack, or the order each node is popped from
: the stack.

P**l
发帖数: 3722
4
这个问题很奇怪呀
都用stack了,显然是pop的顺序啊
要是push就用queue了吧

each node is pushed into the stack, or the order each node is popped from
the stack.

【在 c**********e 的大作中提到】
: In the following graph, with starting point 0, what is the order of DFS
: traversal?
: 0
: / \
: 1 2
: /
: 3
: We use a stack for DFS visit. The problem is, is the visit order the order each node is pushed into the stack, or the order each node is popped from the stack.

r****t
发帖数: 10904
5
Seriously? I thought only pre-order visits nodes in the same order as dfs,
although all three traversal can be implemented using dfs.

【在 q****x 的大作中提到】
: dfs is post-order.
:
: each node is pushed into the stack, or the order each node is popped from
: the stack.

q****x
发帖数: 7404
6
look at clrs graph dfs algorithm. it's post-order. parent node is colored
after children nodes.

【在 r****t 的大作中提到】
: Seriously? I thought only pre-order visits nodes in the same order as dfs,
: although all three traversal can be implemented using dfs.

r****t
发帖数: 10904
7
Fig 22.4?
grey = discovered
black = finished
If visiting is defined as finished, then yes it is post-order;
if visiting is defined as discovered, then it is pre-order.

【在 q****x 的大作中提到】
: look at clrs graph dfs algorithm. it's post-order. parent node is colored
: after children nodes.

c**********e
发帖数: 2007
8
Did you intend to post an attachment?

【在 r****t 的大作中提到】
: Fig 22.4?
: grey = discovered
: black = finished
: If visiting is defined as finished, then yes it is post-order;
: if visiting is defined as discovered, then it is pre-order.

q****x
发帖数: 7404
9
every type of traversal needs to discover root b/4 children.

【在 r****t 的大作中提到】
: Fig 22.4?
: grey = discovered
: black = finished
: If visiting is defined as finished, then yes it is post-order;
: if visiting is defined as discovered, then it is pre-order.

1 (共1页)
进入JobHunting版参与讨论
相关主题
G家电面面经--佛云了~~问一个graph题
L家这题咋搞,巨变态F家电面
bloomberg onsite题print bst in level order dfs为什么是O(N)不应该是O(N^2)吗?
问道题,binary tree里有一个有indegree 2请叫大家一道题
这个题目有什么trick求问一题G家的面经
请教一道面试题图的拷贝
BFS traverse O(1) space?这个check whether a binary tree is a BST 问题
Graph DFS Iterative题目: iterative binary tree post order traversal
相关话题的讨论汇总
话题: order话题: dfs话题: stack话题: node话题: each