Graph Traversal (BFS and DFS) · Algorithms
16 questions · asked in 11 of 27 years (2000–2026)
MCQ 12 · MSQ 2 · NAT 21-mark 12 · 2-mark 4
2000Questions per year2026
Questions 16–16 of 16
Let G be an undirected graph. Consider a depth-first traversal of G, and let T be the resulting depth-first search tree. Let u be a vertex in G and let v be the first new (unvisited) vertex visited after visiting u in the traversal. Which of the following statement is always true?
Answer: (C)
Why C is always true. When DFS discovers , it goes next to an unvisited neighbour of if there is one. That neighbour becomes a child of and is the next new vertex, so would be a neighbour of . So if is not an edge, had no unvisited neighbour, and it has no child. That means is a leaf in .
Why A, B and D can fail. Take the graph to be the tree in the figure and let DFS visit children left to right. The visiting order is G, E, B, D, F, K, M, R. Here and .
- and are not joined by an edge, so A and B fail.
- The parent of is and the parent of is . They are different, so D fails. They only share the ancestor .
Answer: (C)
Keep practising
Topics in Algorithms
SortingAsymptotic NotationRecurrence RelationGreedy TechniqueDynamic ProgrammingDivide and Conquer
Graph Traversal (BFS and DFS)You are here
Minimum Spanning TreeShortest Path