algorithm@ find the shortest path in a graph using BFS
Finding Shortest Paths By BFS
The BFS code we have seen
find outs if there exist a path from a vertex s to a vertex v
prints the vertices of a graph (connected/strongly connected).
What if we want to find
the shortest path from s to a vertex v (or to every other vertex)?
the length of the shortest path from s to a vertex v?
In addition to array flag[ ], use an array named prev[ ], one element per vertex.
prev[w] = v means that vertex w was visited right after v