版权声明:欢迎转载和交流。 https://blog.csdn.net/Hachi_Lin/article/details/88252376
1. The shortest-paths problem
- Distance δ(s, v) : The length of the shortest path from s to v. For example δ(s, c)=2.
- The problem:
- Input: A graph G = (V, E) and a source vertex s∈V
- Question: A shortest path from s to each vertex v ∈V and the distance δ(s, v) .
2. Algorithm
-
Some details:
- White:represented “undiscovered” vertices
- Gray:represented “discovered” but not “processed” vertices
- Black:represented “processed” vertices
-
Given a graph G = <V,E>, the BFS return:
- d[v]:proved to be the shortest distance from s to v
- π[v]:the predecessor of v in the search, which can be used to derive a shortest path from s to vertex v
- BFS acturally returns a shortest path tree in which the unique simple path from s to node v is a shortest path from s to v in the original graph.
3. Example of Breadth-First Search
-
vertex s and a graph G
-
step 1: initialization
-
step 2
-
step 3
-
step 4
-
step 5
-
step 6
-
step 7
-
step 8
-
step 9
4. What does BFS produce
5. Our goal
- δ(s,v) = d[v]