Shortest Path Problems
Introduction Many problems can be modeled using graphs with weights assigned to their edges: 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 chuck if a woodchuck could chuck wood?
Optimal driving time UCLA The Red Garter the beach (dude) In N’ Out 25 The Red Garter 19 5 9 the beach (dude) 21 16 31 In N’ Out 36 My cardboard box on Sunset
Tokyo Subway Map
Applications - Maps (Map Quest, Google Maps) - Routing Systems
Dijkstra's algorithm Steps: 1) Choose/given a starting point. A solution to the single-source shortest path problem in graph theory. Works on both directed and undirected graphs. Steps: 1) Choose/given a starting point. 2) Find the shortest path to the next vertex – label the vertex. 3) Label the remaining vertices from the shortest vertex. 4) Systematically check each vertex to be sure that they are labelled correctly.
Using the previous example, we will find the shortest path from a to c. 25 r 19 9 5 b 16 21 31 i 36 c
(a) = 0 25 (r) = 19 9 5 (b) = 16 21 31 (i) = 36 (c) =
(a) = 0 25 (r) = 19 9 5 (b) = 19 16 21 31 (i) = 36 (c) =
(a) = 0 25 (r) = 19 9 5 (b) = 19 16 21 31 (i) = 35 36 (c) =
(a) = 0 25 (r) = 24 19 9 5 (b) = 19 16 21 31 (i) = 35 36 (c) =
(a) = 0 25 (r) = 24 19 9 5 (b) = 19 16 21 31 (i) = 35 36 (c) = 50
(a) = 0 25 (r) = 24 19 9 5 (b) = 19 16 21 31 (i) = 9 36 (c) = 50
(a) = 0 25 (r) = 24 19 9 5 (b) = 19 16 21 31 (i) = 9 36 (c) = 50
(a) = 0 25 (r) = 24 19 9 5 (b) = 19 16 21 31 (i) = 9 36 (c) = 45
(a) = 0 25 (r) = 24 19 9 5 (b) = 19 16 21 31 (i) = 9 36 (c) = 45
Example ∞ Distance(source) = 0 Distance (all vertices but source) = ∞ ∞ Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E ∞ ∞ ∞ 5 8 4 6 F 1 G ∞ ∞ Pick vertex in List with minimum distance.
Example: Initialization ∞ Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E ∞ ∞ 1 5 8 4 6 F 1 G ∞ ∞
Example 2 Distance(source) = 0 Distance (all vertices but source) = ∞ 2 Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E ∞ ∞ 1 5 8 4 6 F 1 G ∞ ∞
Example 2 Distance(source) = 0 Distance (all vertices but source) = ∞ 2 Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E ∞ 3 1 5 8 4 6 F 1 G ∞ ∞
Example 2 Distance(source) = 0 Distance (all vertices but source) = ∞ 2 Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 F 1 G ∞ ∞
Example 2 Distance(source) = 0 Distance (all vertices but source) = ∞ 2 Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 F 1 G 9 ∞
Example 2 Distance(source) = 0 Distance (all vertices but source) = ∞ 2 Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 F 1 G 9 5
Example 2 Distance(source) = 0 Distance (all vertices but source) = ∞ 2 Distance(source) = 0 Distance (all vertices but source) = ∞ A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 F 1 G 6 5