Shortest Path Problems: Dijkstra's Algorithm
Shortest Path Problems: Dijkstra's Algorithm
Dijkstra’s Algorithm
The Red
19
9
5 Garter
the beach (dude)
16 21
31
In N’ Out
a 25
r
19
9 5
b
16 21
i 31
36 c
Label a with 0 and all others with . L0(a) = 0
and L0(v) =
L0(a) = 0 25
L0(r) =
19
9 5
L0(b) =
16 21
L0(i) = 31
36 L0(c) =
Labels are shortest paths from a to vertices.
S1 = {a, i}
L1(a) = 0 25
L1(r) =
19
9 5
L1(b) =
16 21
L1(i) = 9 31
36 L1(c) =
Lk(a, v) = min{Lk-1(a, v), Lk-1(a, u) + w(u, v)}
S2 = {a, i, b}
L2(a) = 0 25
L2(r) =
19
9 5
L2(b) = 19
16 21
L2(i) = 9 31
36 L2(c) =
S3 = {a, i, b, r}
L3(a) = 0 25
L3(r) = 24
19
9 5
L3(b) = 19
16 21
L3(i) = 9 31
36 L3(c) =
S4 = {a, i, b, r, c}
L4(a) = 0 25
L4(r) = 24
19
9 5
L4(b) = 19
16 21
L4(i) = 9 31
36 L4(c) = 45
Remarks
Implementing this algorithm as a computer
program, it uses O(n2) operations [additions,
comparisons]
Other algorithms exist that account for
negative weights
Dijkstra’s algorithm is a single source one.
Floyd’s algorithm solves for the shortest path
among all pairs of vertices.
Endnotes 1
Endnotes 2
For Math 3975: