600 views
2 votes
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 votes
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

Related questions

4 votes
4 votes
0 answers
1
Na462 asked Aug 21, 2018
3,855 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 votes
0 votes
1 answer
3
VS asked Nov 26, 2017
1,010 views
0 votes
0 votes
0 answers
4