GATE CS 2017 · Set-2 · Graph Traversals (BFS & DFS)

MCQ · 1 mark · Problem PROG-GRPH-0061

The Breadth First Search (BFS) 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.Which one of the following is a possible order of visiting the nodes in the graph?
  1. A
    MNOPQR
  2. B
    NQMPOR
  3. C
    QMNROP
  4. D
    POQNMR

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 its neighbours 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) QMNROP: after Q come M, N, P; R comes before P. Not possible.(D) POQNMR: P's neighbours O, Q; then O's new neighbour N; then Q's new neighbour M; then M's new neighbour R. Possible.Answer: D

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