Skip to main content

GATE CSE 2017Algorithms › Graph AlgorithmsVerified

GATE CSE 2017 PYQ: The Breadth First Search (BFS) algorithm has been implemented using the queue data structure. Which one of…

The Breadth First Search (BFS) algorithm has been implemented using the queue data structure. Which one of the following is a possible order of visiting the nodes in the graph below?

GATE CSE 2017 Graph Algorithms diagram: The Breadth First Search (BFS) algorithm has been implemente

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

Answer

(D) POQNMR \text{POQNMR} POQNMR

Approach

In BFS, vertices are visited in nondecreasing order of their distance from the start vertex; all vertices at distance $k$ must appear before any vertex at distance $k+1$. Check each option against the graph's adjacency relations.

Only option D respects BFS level-ordered traversal: all vertices at a given distance from the start appear before any vertex at a greater distance, and the order is consistent with the graph's adjacency.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.