Download presentation
Presentation is loading. Please wait.
1
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., mapquest.com) for example Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 1
2
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 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 2
3
Dijkstra’s algorithm BOS ORD PVD JFK SFO BWI DFW LAX MIA • • • • • • •
2704 BOS 867 • ORD • 849 PVD 187 1846 144 740 621 • 802 JFK SFO • 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX • 946 1121 • MIA 2342 • Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 3
4
Dijkstra’s algorithm BOS ORD PVD JFK SFO BWI DFW LAX MIA • 621 • • • •
2704 BOS 867 621 • ORD • 849 PVD 187 1846 144 740 621 • 802 JFK SFO • 184 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX • 946 1121 • MIA 2342 946 • Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 4
5
Dijkstra’s algorithm BOS ORD PVD JFK JFK SFO BWI DFW LAX MIA • 621 • •
2704 BOS 867 621 ORD • 849 PVD 187 1846 144 740 621 • 802 JFK JFK SFO 184 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX • 946 1121 • MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 5
6
Dijkstra’s algorithm BOS ORD PVD PVD JFK SFO BWI DFW LAX MIA 371 621
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 DFW 1235 LAX 1575 946 1121 • MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 6
7
Dijkstra’s algorithm BOS BOS ORD PVD JFK SFO BWI DFW LAX MIA 371 621
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 DFW 1235 LAX 1575 946 1121 • MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 7
8
Dijkstra’s algorithm BOS ORD ORD PVD JFK SFO BWI DFW LAX MIA 371 621
2704 BOS 867 621 ORD ORD 328 849 PVD 187 1846 144 740 621 3075 2467 802 JFK SFO 184 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 1575 1423 946 1121 • MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 8
9
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 DFW 1235 LAX 1423 946 1121 3288 • MIA MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 9
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 DFW DFW 1235 LAX 1423 946 1121 2658 3288 MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10
11
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 DFW 1235 LAX 1423 946 1121 2658 MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 11
12
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 DFW 1235 LAX LAX 1423 946 1121 2658 MIA 2342 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 12
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.