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

posted @ 2016-03-16 03:34  流白  阅读(625)  评论(0编辑  收藏  举报