Similar questions 1 more →
Graph Algorithms

Answer & solution
Official answer: D
Step through it (4 options)
1. BFS removes vertices from a FIFO queue and discovers all vertices at a smaller distance before any at a larger distance. For D, start at P and enqueue its neighbors O then Q. The visited prefix is P,O,Q.
2. Processing O discovers N; its other neighbors P and Q are already discovered. Processing Q then discovers M, with N already queued. Processing N adds nothing, and processing M finally discovers R. The resulting order is P,O,Q,N,M,R.
3. A fails from M because O at distance 2 precedes its distance-1 neighbors Q and R. B fails from N because P at distance 2 precedes O at distance 1. C fails from Q because R at distance 2 precedes O and P at distance 1. Thus D is possible; BFS neighbor ordering need not be alphabetical.