Consider the following graph:

Among the following sequences:
- abeghf
- abfehg
- abfhge
- afghbe
Which are the depth-first traversals of the above graph?
View worked solution
Answer: D
The given graph has the vertex set with the following edge connections:
- is connected to
- is connected to
- is connected to
- is connected to
- is connected to
- is connected to
Let's analyze each sequence using Depth-First Search (DFS) rules:
- I. : Valid. From , we visit , then , then , then , and finally . All steps follow valid unvisited adjacent edges.
- II. : Invalid. After visiting , we backtrack to to visit . From , the only unvisited neighbor is . In DFS, we must explore the unvisited neighbor before backtracking. Thus, we cannot jump to from or backtrack to to reach while remains unvisited.
- III. : Valid. From , the only unvisited vertex left is , which is directly connected to the current vertex .
- IV. : Valid. From , the only unvisited vertex left is , which is directly connected to the current vertex .
Thus, sequences I, III, and IV are valid depth-first traversals.
Free practice · Your answers on this page are not saved.
