How we have to print the distance from the source vertex?? If some node is not connected directly to the source then we have to print -1??
In BFS-Shortest Path
if a vertex is not directly connected to source, it may be having some path from source to that vertex.
for example: 1->2->3 in this path, distance of vertex 3 from 1 is 2, so in this case, you will print 2(for vertex 3)
disconnected implies you cannot reach a vertex irrespective of the path you follow.
for example: 1->2 3, here 3 is disconnected from 1, so you will print -1(for vertex 3)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
Refer this -:
Comments are added.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.