Consider an undirected, unweighted graph . Let a breadth-first traversal of be done starting from a node . Let and be the lengths of the shortest paths from to and respectively in . If is visited before during the breadth-first traversal, which of the following statements is correct?
View worked solution
Answer: C
Breadth-First Search (BFS) on an undirected, unweighted graph visits vertices in non-decreasing order of their shortest path distance from the starting node .
Let denote the shortest path distance from to any node . During BFS:
- Nodes at distance are always visited before nodes at distance .
- Nodes at the same distance are visited in the order they are enqueued, which depends on the structure of the adjacency list.
Thus, if is visited before , there are two possibilities:
- is closer to than , meaning .
- and are at the same distance from , meaning , but happened to be enqueued before .
Combining these two cases, we get:
Counter-example for Option A:
Consider a graph with three vertices and edges and .
- The shortest path distances are and .
- Starting BFS from , we can visit first and then . Here, is visited before , but .
- This disproves option A ().
Therefore, the correct statement is .
Free practice · Your answers on this page are not saved.
