next up previous
Next: Up: Previous:

Properties

\(\delta(s,v)\) = shortest-path distance from s to v

Theorem 23.4

G = (V, E) directed or undirected
BFS(G, s), s in V
Upon termination of BFS, every vertex v in V reachable from s has
distance(v) =
\(\delta(s,v)\)
For vertex v
$\neq$ s reachable from s, one shortest path from s to v is the shortest path from s to pred(v) followed by edge (pred(v), v)



Proof: by induction on distance from s



Print-Path(G, s, v) $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; O(V)
$\;\;\;\;\;$if v = s
$\;\;\;\;\;$then print s
$\;\;\;\;\;$else if pred(v) = NIL
$\;\;\;\;\;$ $\;\;\;\;\;$then "no path"
$\;\;\;\;\;$ $\;\;\;\;\;$else Print-Path(G, s, pred(v))
$\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$print v


next up previous
Next: Up: Previous: