Why is this algorithm correct?
Theorem: At the termination of the algorithm, Dist(v) is the length of the shortest path from s to v for each vertex v of G.
Proof: by induction on |V-U|.
Inductive hypothesis: Let |V-U|=k.
- for every v in V-U, Dist(v) is length of shortest path from s to v
- the vertices in V-U are the k closest vertices to s.
- for every v in U, Dist(v) is the length of shortest path from s to v that only goes through vertices in V-U.