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 2017Algorithms › Graph AlgorithmsVerified
GATE CSE 2017 PYQ: The Breadth First Search (BFS) algorithm has been implemented using the queue data structure. Which one of…
- A
- B
- C
- DCorrect 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.