Skip to content
Official PYQ · 2000

GATE CS 2000 Q2.19 — Graph Traversals (BFS, DFS)

Explain with AI

Let GG be an undirected graph. Consider a depth-first traversal of GG, and let TT be the resulting depth-first search tree. Let uu be a vertex in GG and let vv be the first new (unvisited) vertex visited after visiting uu in the traversal. Which of the following statement is always true?

Choose one option
View worked solution

Answer: C

To determine which statement is always true, let us analyze the behavior of Depth-First Search (DFS) when we are at vertex uu:

  1. Case 1: uu has at least one unvisited neighbor in GG.
    The DFS algorithm will immediately select one of these unvisited neighbors, say vv, and visit it next.
    • In this case, (u,v)(u, v) is an edge in GG.
    • vv becomes a child of uu in the DFS tree TT, making vv a descendant of uu.
  2. Case 2: uu has no unvisited neighbors in GG.
    Since there are no unvisited neighbors to explore directly from uu, the DFS algorithm must backtrack from uu.
    • Because no new vertex is visited directly from uu, uu has no children in TT. Thus, uu is a leaf in TT.
    • The search backtracks to some ancestor of uu to find the next unvisited vertex vv. Since vv is not a neighbor of uu, the set {u,v}\{u, v\} is not an edge in GG.

From Case 2, we can see that if {u,v}\{u, v\} is not an edge in GG, then uu must have had no unvisited neighbors when it was reached, meaning we backtracked from it immediately. Thus, uu must be a leaf in TT. This makes Option C always true.


Counterexample for Option D:

Consider a tree graph with edges {1,2}\{1, 2\}, {2,3}\{2, 3\}, and {1,4}\{1, 4\}.

  • Start DFS at 11.
  • Visit sequence: 1→2→31 \to 2 \to 3.
  • At u=3u = 3, there are no unvisited neighbors. We backtrack to 22, then to 11.
  • From 11, we visit the next unvisited vertex v=4v = 4.

Here, {3,4}\{3, 4\} is not an edge in GG. However, the parent of 33 is 22, and the parent of 44 is 11. They do not share the same parent, which disproves Option D.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Graph Traversals (BFS, DFS) questions