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

algorithm@ find the shortest path in a graph using BFS_第1张图片algorithm@ find the shortest path in a graph using BFS_第2张图片algorithm@ find the shortest path in a graph using BFS_第3张图片algorithm@ find the shortest path in a graph using BFS_第4张图片algorithm@ find the shortest path in a graph using BFS_第5张图片algorithm@ find the shortest path in a graph using BFS_第6张图片algorithm@ find the shortest path in a graph using BFS_第7张图片algorithm@ find the shortest path in a graph using BFS_第8张图片algorithm@ find the shortest path in a graph using BFS_第9张图片algorithm@ find the shortest path in a graph using BFS_第10张图片algorithm@ find the shortest path in a graph using BFS_第11张图片algorithm@ find the shortest path in a graph using BFS_第12张图片algorithm@ find the shortest path in a graph using BFS_第13张图片algorithm@ find the shortest path in a graph using BFS_第14张图片algorithm@ find the shortest path in a graph using BFS_第15张图片

你可能感兴趣的:(algorithm@ find the shortest path in a graph using BFS)