1,057 views
2 2 votes

While doing BFS , at any time in queue suppose there are r vertices v1,v2,v3.....vr with v.d as the distance from the source.

Then according to me at any time in a queue,

v1.d=v2.d

or

v2.d=v1.d+1

But in cormen its written that v2.d<=v1.d+1

Can someone please explain?

1 Answer

Best answer
3 3 votes

Fig 1 is Graph G

Fig 2 is BFS done on graph G

Bold Colour Edges in fig 2 are BFS Tree edges.

At Right side, instances of Queue 'Q' is derived.

Observe at instance no. 4 ., distance from source 's' to 'w' & 'v' is 1 & 2 respectively.

similarly at instance no 7, distance from source 's' to 'x' & 'u' is 2 & 3.

Therefore, v2.d <= v1.d + 1

• selected by
Position:
Show:

Related questions

4 4 votes
0 0 answers
5.6k
5.6k views
Na462 asked Aug 21, 2018
5,617 views
Which of following statement is true ?A. In BFS of UDG there are no back edges and forward edges.B. In BFS of Directed Graph there is no back edge and forward edges.C. In...
0 0 votes
0 0 answers
737
737 views
Lakshman Bhaiya asked Nov 13, 2018
737 views
$0-1$ $BFS$ (Breadth First Search)al is used to find the shortest distance between two nodes in a graph providedthat the edges in the graph have the weights $0$ or $1.$Wh...
0 0 votes
1 1 answer
2.3k
2.3k views
VS asked Nov 26, 2017
2,348 views
Consider the following graph G.The BFS traversal on G is modified as : The starting vertex for traversal will be 'a'. At any level (breadth), vertices are visited in alph...
0 0 votes
0 0 answers
1.0k
1.0k views
akshat sharma asked Mar 21, 2018
1,019 views
State True or False with explanation The depth of a breadth-first search tree on an undirected graph $G = (V, E)$ from an arbitrary vertex $v \in V$ is the diameter of th...