The GATE Grind

GATE 2017 CS (CS2) – Question 25

Algorithms · Graph Algorithms: Traversals, Minimum Spanning Trees, Shortest Paths · 1 mark · Multiple choice

BFS is implemented using a queue. Which is a possible vertex-visiting order for the shown graph?

Diagram for GATE 2017 CS (CS2) question 25
  1. MNOPQR
  2. NQMPOR
  3. QMNROP
  4. POQNMR

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) POQNMR

Explanation

Start at P: its distance-one neighbours are O,Q and its distance-two vertices are N,M. R is reached from M at distance three. Choosing neighbour order O,Q and then N,M produces P,O,Q,N,M,R. This is D. The other sequences place a farther vertex before a nearer one or violate queue discovery order.

More Graph Algorithms: Traversals, Minimum Spanning Trees, Shortest Paths questions

All Graph Algorithms: Traversals, Minimum Spanning Trees, Shortest Paths questions →