Shortest Path Problems Dijkstras Algorithm TAT 01 Michelle
Shortest Path Problems Dijkstra’s Algorithm TAT ’ 01 Michelle Wang
Introduction Many problems can be modeled using graphs with weights assigned to their edges: n n n Airline flight times Telephone communication costs Computer networks response times
Where’s my motivation? Fastest way to get to school by car Finding the cheapest flight home How much wood could a woodchuck if a woodchuck could chuck wood?
Optimal driving time UCLA 9 In N’ Out 25 19 5 The Red Garter the beach (dude) 16 36 31 21 My cardboard box on Sunset
Tokyo Subway Map
Setup: § G = weighted graph § In our version, need POSITIVE weights. § G is a simple connected graph. § § A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. A labeling procedure is carried out at each iteration § A vertex w is labeled with the length of the shortest path from a to w that contains only the vertices already in the distinguished set.
Outline of Algorithm Label a with 0 and all others with . L 0(a) = 0 and L 0(v) = Labels are shortest paths from a to vertices Sk = the distinguished set of vertices after k iterations. S 0 = . The set Sk is formed by adding a vertex u NOT in Sk-1 with the smallest label. Once u is added to Sk we update the labels of all the vertices not in Sk To update labels: Lk(a, v) = min{Lk-1(a, v), Lk-1(a, u) + w(u, v)}
Using the previous example, we will find the shortest path from a to c. a 25 r 19 9 5 b 16 31 i 36 c 21
Label a with 0 and all others with . L 0(a) = 0 and L 0(v) = L 0(a) = 0 25 L 0(r) = 19 9 L 0(b) = 16 31 L 0(i) = 36 L 0(c) = 5 21
Labels are shortest paths from a to vertices. S 1 = {a, i} L 1(a) = 0 25 L 1(r) = 19 9 L 1(b) = 16 31 L 1(i) = 9 36 L 1(c) = 5 21
Lk(a, v) = min{Lk-1(a, v), Lk-1(a, u) + w(u, v)} S 2 = {a, i, b} L 2(a) = 0 25 L 2(r) = 19 9 L 2(b) = 19 16 31 L 2(i) = 9 36 L 2(c) = 5 21
S 3 = {a, i, b, r} L 3(a) = 0 25 L 3(r) = 24 19 9 L 3(b) = 19 16 31 L 3(i) = 9 36 L 3(c) = 5 21
S 4 = {a, i, b, r, c} L 4(a) = 0 25 L 4(r) = 24 19 9 L 4(b) = 19 16 31 L 4(i) = 9 36 L 4(c) = 45 5 21
Remarks Implementing this algorithm as a computer program, it uses O(n 2) 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:
- Slides: 17