edited by
3,867 views
6 votes
6 votes

Consider the following graph:

The minimum size of queue required when performing BFS on above graph is ________.
(Size of queue is represented by maximum number of element at any time).

edited by

3 Answers

6 votes
6 votes

Minimum size means the size of queue which is sufficient for all cases (i.e. no matter from where the BFS starts, the queue will never overflow). Also this size should be minimum over all the other sizes which are sufficient.

Now since node E has 4 neighbours, the min size required to complete BFS, if the starting node is E, is 4.

Hence 4 is the answer.

1 votes
1 votes

Start from c...Pushed C

Pop E and then we need to push B,E,D,G...then pop G and push A,F...

Hence answer must be..... 5

edited by
1 votes
1 votes
Queues size always equals to   number of vertices.

Hence    queue size is  always  in this question = # of vertices  7 ( min Or max case ) .

 

Max size of stack   :- means  no pop operation will occurs   in dfs ( stack) ..     Hence   here  we start   vertices A  .  

Sequence is    A B C D G E F   max size of stack is  7 .

Min size of stack :- means choose a path where more number of operation done.    

Sequence for minimum :- F E C D G B A    HERE   after C  ,   path  c d g  push in stack   and after   delet  g and d  from stack   .  Now we at point C,  and now onwards we add   b and a in stack.....      Hence total minimum size is    5 .
1 flag:
✌ Low quality (merohan17` “Wrong solution”)

Related questions

0 votes
0 votes
2 answers
1
1 votes
1 votes
0 answers
2
1 votes
1 votes
0 answers
4