next up previous
Next: Predecessor Subgraph Up: CSE 2320: Algorithms and Previous: Analysis


\(\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) =
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

Copyright © 1998 The University of Texas at Arlington