Amazon Interview Question
Software Engineer / DevelopersFirst about DFS: It can be InOrder, PreOrder or PostOrder. How to modify it to BFS?
well the question is not quite clear here. Should the BFS be implemented using DFS?
BFS can be implemented using queues.
Second: Topological Sort outputs those vertices with indegrees of 0 first, removing them, find the remaining vertices of indegree 0 until the whole graph is exhausted. (Well indegree means the number of incoming edges on a vertex in a graph). This also can be implemented using queues.
I think DFS is equivalent to post-order transverse, not to in-order or pre-order. Using a stack to post-order transverse a binary tree has pretty complicate logic.
topologival sort is ancestor sort, means parent should also apprea before the their child in a sorting sequence.
- Anonymous June 08, 2010