Skip to main content

GATE CSE 2008Algorithms › Graph AlgorithmsVerified

GATE CSE 2008 PYQ: The Breadth First Search algorithm has been implemented using the queue data structure. One possible order…

The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is:

GATE CSE 2008 Graph Algorithms diagram: The Breadth First Search algorithm has been implemented usin

  1. A
    MNOPQR\text{MNOPQR}
  2. B
    NQMPOR\text{NQMPOR}
  3. C
    QMNPRO\text{QMNPRO}
    Correct answer
  4. D
    QMNPOR\text{QMNPOR}

Answer

(C) QMNPRO \text{QMNPRO} QMNPRO

Approach

Read the undirected graph from the figure and reconstruct its adjacency list. Then run BFS mentally from each candidate start node given in the options, checking (i) that all distance-1 neighbours of the start are visited before any distance-2 node, and (ii) that within a BFS level the queue order is respected. Any option that violates the level-by-level visitation property of BFS is eliminated.

BFS visits nodes strictly in non-decreasing order of distance from the source and respects queue (FIFO) ordering within and across levels. Only QMNPOR satisfies this for the given graph: starting from Q, the queue processes M (adding R), then N (adding O), then P, then R, then O, producing Q-M-N-P-R-O. Options A and B place a level-2 node (O or P) ahead of level-1 nodes, and option D reverses the required queue order of R and O.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.