40 40 votes 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? $\text{MNOPQR}$ $\text{NQMPOR}$ $\text{QMNROP}$ $\text{POQNMR}$ Algorithms gatecse-2017-set2 algorithms graph-algorithms graph-search + – Madhav 13.1k views answer comment Share Follow Print See 1 comment 1 1 comment reply register_user_19 commented Dec 3, 2018 reply Follow flag same question asked in 2008 https://gateoverflow.in/417/gate2008-19 conclusion: Do all the previous year question. (all means all even subjective also) 15 15 replyShare Please log in or register to add a comment.
Best answer 32 32 votes In BFS, starting from a node, we traverse all node adjacent to it at first then repeat same for next nodes. Here, we can see that only option (D) is following BFS sequence properly. As per BFS, if we start from $M$ then $RQN$ $($immediate neighbors of $M)$ have to come after it in any order but in $A$ here, $O$ comes in between. So, it is not BFS. As per BFS, if we start from $N$ then $QMO$ has to come after it in any order but in $B$ here, $P$ comes. So, it is not BFS. As per BFS, if we start from $Q$ then $MNOP$ has to come after it in any order but in $C$ here, $R$ comes. So, it is not BFS. But $D$ is following the sequences. So, D is the correct answer. Aboveallplayer answered Feb 14, 2017 • edited Jun 25, 2018 by Shikha Mallick Aboveallplayer comment Share Follow See 1 comment 1 1 comment reply pavansan commented Jan 2, 2025 reply Follow flag actually i was confused between c and d luckily put d 0 0 replyShare Please log in or register to add a comment.
4 4 votes ans is D. 2018 answered Feb 14, 2017 2018 comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote (D) We traverse and process the nodes of the graph one level at a time. All options except D have skipped levels. Kloseup answered Feb 14, 2017 Kloseup comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes It will be d) gargshreya answered Feb 14, 2017 gargshreya comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes The possible order of visiting the nodes in Breadth First Search Algorithm, implementing using Queue Data Structure is (Do it by option Elimination) (a) MNOPQR – MNO is not the proper order R must come in between. (b) NQMPOR – QMP is not the order O is the child of N. (C) QMNROP – M is not the child of Q, so QMN is false. (D) POQNMR – P → OQ → NMR is the correct sequence. Hence Option (D). varunrajarathnam answered Aug 7, 2020 varunrajarathnam comment Share Follow 0 reply Please log in or register to add a comment.