CSE 421 Greedy Algorithms Dijkstras Algorithm Yin Tat

  • Slides: 38
Download presentation
CSE 421 Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee 1

CSE 421 Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee 1

Single Source Shortest Path •

Single Source Shortest Path •

Dijkstra’s Algorithm: Example s 0 2 4 5 7 4 6 3 1 9

Dijkstra’s Algorithm: Example s 0 2 4 5 7 4 6 3 1 9 4 5 10 8 2 3 1 5 8

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 4 6 3

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 4 6 3 1 9 4 5 10 8 2 3 1 5 8

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 4 6 3

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 4 6 3 1 9 4 5 10 8 2 3 1 5 8

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 9 4 5 10 8 2 3 1 5 8

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 9 4 5 10 8 2 3 1 5 8

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 8 9 4 5 10 8 2 3 1 7 5 5 8

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 8 9 4 5 10 8 2 3 1 7 5 5 8

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 8 9 4 5 10 8 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 8 9 4 5 10 8 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 8 9 4 5 10 8 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 8 9 4 5 10 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 1 8 9 4 5 10 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 5 10 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 5 10 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 14 5 10 20 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 14 5 10 20 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 14 5 10 19 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 14 5 10 19 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 14 5 10 18 8 16 2 3 1 7 5 5 8 13

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6

Dijkstra’s Algorithm: Example s 0 2 2 4 4 5 7 9 4 6 3 15 1 8 9 4 10 14 5 10 18 8 3 1 7 5 5 8 13 16 2 Dijkstra’s Algorithm outputs a tree.

Remarks on Dijkstra’s Algorithm •

Remarks on Dijkstra’s Algorithm •

Implementing Dijkstra’s Algorithm •

Implementing Dijkstra’s Algorithm •

Disjkstra’s Algorithm: Correctness • y s x S u v

Disjkstra’s Algorithm: Correctness • y s x S u v

Dijkstra Example 1. 6 million vertices 3. 8 million edges Distance = travel time.

Dijkstra Example 1. 6 million vertices 3. 8 million edges Distance = travel time. Images comes from A. V. Goldberg

Dijkstra Example Searched Area (starting from green point)

Dijkstra Example Searched Area (starting from green point)

340 ms Bidirectional Dijkstra Forward search Backward search

340 ms Bidirectional Dijkstra Forward search Backward search

BFS Dijkstra

BFS Dijkstra

Estimating the distance

Estimating the distance

12 ms Forward search Backward search Inactive landmarks Active landmarks Problem of ATL: We

12 ms Forward search Backward search Inactive landmarks Active landmarks Problem of ATL: We should stick with highway! From now on, we allow to preprocess the graph.

30 ms Reach Algorithm Use highway except for the beginning and the end of

30 ms Reach Algorithm Use highway except for the beginning and the end of the journey! Forward search Backward search

Creating shortcut in the graph When you are on the highway, don’t need to

Creating shortcut in the graph When you are on the highway, don’t need to keep checking the map until you are nearby!

2 ms Reach + Shortcut Algorithm Forward search Backward search

2 ms Reach + Shortcut Algorithm Forward search Backward search

0. 7 ms Reach + Shortcut + ATL Algorithm

0. 7 ms Reach + Shortcut + ATL Algorithm