GATE CS 2008 · Shortest Path Algorithms

MCQ · 1 mark · Problem PROG-GRPH-0095

The Breadth First Search algorithm has been implemented using the queue data structure. Consider the undirected graph with vertices M, N, O, P, Q, R and the 7 edges M-N, M-Q, M-R, N-O, N-Q, O-P, P-Q.One possible order of visiting the nodes of the graph is
  1. A
    MNOPQR
  2. B
    NQMPOR
  3. C
    QMNPRO
  4. D
    QMNPOR

Solve it on GATE DA practice →More Graph Theory & Algorithms problems

Show the worked solution\[\boxed{\text{BFS: all unvisited neighbours of a vertex are visited before any vertex found later}}\]Neighbours: M: N, Q, R. N: M, O, Q. O: N, P. P: O, Q. Q: M, N, P. R: M.(A) MNOPQR: after M come N, Q, R; O comes too early. Not possible.(B) NQMPOR: after N come M, O, Q; P is not a neighbour of N. Not possible.(C) QMNPRO: Q's neighbours M, N, P; then M's new neighbour R; then N's new neighbour O. Possible.(D) QMNPOR: after Q, M, N, P the next vertex must be M's new neighbour R, not O. Not possible.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com