GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 19

Valid queue-based BFS order

Algorithms · Graph Algorithms · Full GATE CSE 2008 paper

GATE 2008, Q19 1 mark · MCQ
Report issue

Graph Algorithms

Question 19, GATE 2008: An undirected graph has vertices M,N,O,P,Q,R and edges MN,NO,OP,PQ,QM,QN,MR. Which is a possible queue-based breadth-first traversal?

(A) MNOPQR
(B) NQMPOR
(C) QMNPRO
(D) QMNPOR
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step through it (4 options)

1. BFS uses a FIFO queue, so all newly discovered neighbors enter behind previously queued vertices. Start at Q and discover M,N,P in that order.
2. Processing M next discovers R. Processing N then discovers O. Processing P adds nothing because O is already discovered.
3. The dequeue/visit order is Q,M,N,P,R,O, C. D puts O before R despite the specified first-layer order; the other offered orders violate BFS layers.

Original paper, page 4