1 / 13

Shortest Paths and Dijkstra’s Algorithm

Shortest Paths and Dijkstra’s Algorithm. CS 105. 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

esmeraldaa
Download Presentation

Shortest Paths and Dijkstra’s Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shortest Paths andDijkstra’s Algorithm CS 105

  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. 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( n2 log n ),O( n2 ) if computation of minimum is simplified

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

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

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

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

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

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

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

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

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

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

More Related