GATE | GATE-CS-2000 | Question 49

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 statements is always true?
(A) {u,v} must be an edge in G, and u is a descendant of v in T
(B) {u,v} must be an edge in G, and v is a descendant of u in T
(C) If {u,v} is not an edge in G then u is a leaf in T
(D) If {u,v} is not an edge in G then u and v must have the same parent in T

Answer: (C)


In DFS, if 'v' is visited
after 'u', then one of the following is true.
1) (u, v) is an edge.
   /   \
  v     w
 /     / \
x     y   z

2) 'u' is a leaf node.
   /   \
  x     v
 /     / \
u     y   z 

In DFS, after visiting a node, we first recur for all unvisited children. If there are no unvisited children (u is leaf), then control goes back to parent and parent then visits next unvisited children.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.