Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shortest Paths and Dijkstra’s Algorithm CS 105. SSSP Slide 2 Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine.

Similar presentations


Presentation on theme: "Shortest Paths and Dijkstra’s Algorithm CS 105. SSSP Slide 2 Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine."— Presentation transcript:

1 Shortest Paths and Dijkstra’s Algorithm CS 105

2 SSSP Slide 2 Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine the shortest paths from v to all other vertices in G Path length: sum of all edges in path Useful in road map applications (e.g., google maps or map quest) for example

3 SSSP Slide 3 Dijkstra’s Algorithm Solves the single-source shortest paths problem Involves keeping a table of current shortest path lengths from source vertex (initialize to infinity for all vertices except v, which has length 0) Repeatedly select the vertex u with shortest path length, and update other lengths by considering the path that passes through that vertex Stop when all vertices have been selected Could use a priority queue to facilitate selection of shortest lengths Need to refine data structure so that the update of key-values in priority queue is allowed Time complexity: O( (n + m) log n ) or O( n 2 log n ), O( n 2 ) if computation of minimum is simplified

4 SSSP Slide 4 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO 0 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704

5 SSSP Slide 5 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO 184 0 946 621 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704

6 SSSP Slide 6 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO 184 0 946 621 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 JFK

7 SSSP Slide 7 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO 371 328 184 0 946 621 1575 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 PVD

8 SSSP Slide 8 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO 371 328 184 0 946 621 1575 3075 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 BOS

9 SSSP Slide 9 3075 1575 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO 371 328 184 0 946 621 1423 2467 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 ORD

10 SSSP Slide 10 Dijkstra’s algorithm (cont) ORD BOS PVD JFK BWI MIA DFW LAX SFO 371 328 184 0 946 621 1423 3288 2467 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 MIA

11 SSSP Slide 11 3288 Dijkstra’s algorithm (cont) ORD BOS PVD JFK MIA DFW LAX SFO 371 328 184 0 946 621 1423 2658 2467 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 BWI DFW

12 SSSP Slide 12 Dijkstra’s algorithm (cont) LAX SFO 371 328 184 0 946 621 1423 2658 2467 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 ORD BOS PVD JFK BWI MIA DFW SFO

13 SSSP Slide 13 Dijkstra’s algorithm (cont) LAX SFO 371 328 184 0 946 621 1423 2658 2467 849 867 187 144 184 1258 1090 946 740 621 1391 802 1121 2342 1235 1464 337 1846 2704 ORD BOS PVD JFK BWI MIA DFW LAX


Download ppt "Shortest Paths and Dijkstra’s Algorithm CS 105. SSSP Slide 2 Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine."

Similar presentations


Ads by Google