next up previous
Next: About this document Up: One-to-all Shortest Paths Previous: Bellman-Ford Algorithm

DIJKSTRA's ALGORITHM

Let all weights be non-negative. Uses a priority queue Q. DIJIKSTRA(G)

for each tex2html_wrap_inline316 , tex2html_wrap_inline684
tex2html_wrap_inline682
Shortest Path Tree tex2html_wrap_inline688
tex2html_wrap_inline690 prioritized by their d[] labels.
while tex2html_wrap_inline694
tex2html_wrap_inline696
tex2html_wrap_inline698
for each tex2html_wrap_inline694
if d[v] > d[u]+w(u,v)
then tex2html_wrap_inline652
Correctness: Prove that whenever u is added to S, tex2html_wrap_inline710
Theorem 25.10
Proof: Basically same as in book, but derives a different contradiction.
Figure 25.6
Note that tex2html_wrap_inline706
(because lemma proved for Bellman-Ford above was just about relaxation, didn't depend on order of relaxing edges)
Let u be first vertex picked such that shorter path than tex2html_wrap_inline710
Let y be first vertex tex2html_wrap_inline712 on actual shortest path from s to u tex2html_wrap_inline718

Because:

d[x] is set correctly for y's [predecessor tex2html_wrap_inline722 on the shortest path (by choice of u as first choice for which that's not true)
when put x into S, relaxed (x,y), giving d[y] correct value,
d[u]> (s,u)
= (s,y)+ (y,u) (optimal substructure)
=d[y]+ (y,u)
tex2html_wrap_inline740 (no negative weights)

But tex2html_wrap_inline742 algorithm would have chosen y to process next, not u.
Contradiction.



Sushil Prasad
Thu Nov 4 14:09:59 EST 1999