GATE | GATE-CS-2017 (Set 2) | Question 22

Breath First Search(BFS) has been implemented using queue data structure.

g2017_15

Which one of the following is a possible order of visiting the nodes in the graph above.
(A) MNOPQR
(B) NQMPOR
(C) QMNROP
(D) POQNMR


Answer: (D)

Explanation: In BFS, we print a starting node, then its adjacent, then adjacent of adjacent, and so on..



Option A : MNOPQR Wrong
We cannot visit "O" before "R" as we start from "M". 
Note that "O" is adjacent of adjacent for "M" and
"R" is adjacent of "M".

Option B : NQMPOR Wrong
We cannot visit "P" before "O" as we start from "N". 
Note that "P" is adjacent of adjacent for "N" and 
"O" is adjacent.

Option C : QMNROP Wrong
We cannot visit "R" before "O" as we start from "Q". 
Note that "R" is adjacent of adjacent for "Q" and
"O" is adjacent of "Q"

Option D : POQNMR Right
We visit "P", then its adjacent "O", "Q" and "N"
Finally we visit adjacent of adjacent "M" and "R"


Quiz of this Question



My Personal Notes arrow_drop_up