Similar questions 2 more →
Graph Algorithms

Answer & solution
Answer: D (no official key was published)
1. Approach. All edges have equal cost, so distance is the number of edges. A FIFO queue processes every distance-d vertex before any distance-(d+1) vertex.
2. Derivation and interpretation. BFS starts at S and discovers vertices in increasing number of edges from S. When a vertex is first discovered, its level is its shortest-path distance; parent pointers recover paths. With adjacency lists, every vertex and edge is processed O(1) times, giving O(V+E). DFS does not generally find shortest paths; generic Dijkstra adds priority-queue overhead, and Warshall solves a more expensive all-pairs/reachability problem. Thus D is the appropriate algorithm.