edited by
13,118 views
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?

  1. $\text{MNOPQR}$
  2. $\text{NQMPOR}$
  3. $\text{QMNROP}$
  4. $\text{POQNMR}$

5 Answers

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.

edited by
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.
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).

Answer:
Position:
Show:

Related questions

71 71 votes
10 answers 10 answers
23.9k
23.9k views
Akash Kanase asked Feb 12, 2016
23,948 views
Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex $t$ at a distance four from the root. If $t$ is the $n^{\text{th}...
65 65 votes
9 answers 9 answers
18.5k
18.5k views
go_editor asked Sep 28, 2014
18,513 views
Consider the tree arcs of a BFS traversal from a source node $W$ in an unweighted, connected, undirected graph. The tree $T$ formed by the tree arcs is a data structure f...
93 93 votes
16 answers 16 answers
32.5k
32.5k views
Misbah Ghaya asked Feb 13, 2015
32,541 views
Let $G = (V, E)$ be a simple undirected graph, and $s$ be a particular vertex in it called the source. For $x \in V$, let $d(x)$ denote the shortest distance in $G$ from ...
63 63 votes
5 answers 5 answers
32.6k
32.6k views
go_editor asked Sep 28, 2014
32,632 views
Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first checkin...