Let be an undirected graph. Consider a depth-first traversal of , and let be the resulting depth-first search tree. Let be a vertex in and let be the first new (unvisited) vertex visited after visiting in the traversal. Which of the following statement is always true?
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 :
-
Case 1: has at least one unvisited neighbor in .
The DFS algorithm will immediately select one of these unvisited neighbors, say , and visit it next.- In this case, is an edge in .
- becomes a child of in the DFS tree , making a descendant of .
-
Case 2: has no unvisited neighbors in .
Since there are no unvisited neighbors to explore directly from , the DFS algorithm must backtrack from .- Because no new vertex is visited directly from , has no children in . Thus, is a leaf in .
- The search backtracks to some ancestor of to find the next unvisited vertex . Since is not a neighbor of , the set is not an edge in .
From Case 2, we can see that if is not an edge in , then must have had no unvisited neighbors when it was reached, meaning we backtracked from it immediately. Thus, must be a leaf in . This makes Option C always true.
Counterexample for Option D:
Consider a tree graph with edges , , and .
- Start DFS at .
- Visit sequence: .
- At , there are no unvisited neighbors. We backtrack to , then to .
- From , we visit the next unvisited vertex .
Here, is not an edge in . However, the parent of is , and the parent of is . They do not share the same parent, which disproves Option D.
Free practice · Your answers on this page are not saved.
