Singlesource shortest paths n Given a weighted graph
- Slides: 12
Single-source shortest paths n Given a weighted graph G and a source vertex v in G, determine the shortest paths from v to all other vertices in G n n 10/02/05 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 10/02/05
Dijkstra’s Algorithm n n n 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 n n 10/02/05 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 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm • 2704 ORD 849 740 621 1464 1235 DFW • 2342 BWI 1090 946 1121 • 10/02/05 1258 1391 0 LAX • 184 337 • 144 JFK 802 SFO PVD 187 1846 • BOS 867 • MIA • Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm • 2704 ORD 849 740 621 1464 1235 DFW • 2342 BWI 1090 946 1121 • 10/02/05 1258 1391 0 LAX 184 • 184 337 • 144 JFK 802 SFO PVD 187 1846 • BOS 867 621 • MIA 946 • Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm • 2704 ORD 849 740 621 1464 1235 DFW • 2342 BWI 1090 946 1121 • 10/02/05 1258 1391 0 LAX 184 337 • 144 JFK 802 SFO PVD 187 1846 • BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm 371 2704 ORD 849 740 621 1464 1235 DFW 1575 2342 BWI 1090 946 1121 • 10/02/05 1258 1391 0 LAX 184 337 328 144 JFK 802 SFO PVD 187 1846 • BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm 371 2704 ORD 849 740 621 1464 1235 DFW 1575 2342 BWI 1090 946 1121 • 10/02/05 1258 1391 0 LAX 184 337 328 144 JFK 802 SFO PVD 187 1846 3075 • BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm 371 2704 ORD 849 740 621 1464 1235 DFW 1575 1423 2342 BWI 1090 946 1121 • 10/02/05 1258 1391 0 LAX 184 337 328 144 JFK 802 SFO PVD 187 1846 3075 2467 BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm (cont) 371 2704 ORD 849 740 621 1464 1235 DFW 1423 2342 BWI 1090 946 1121 3288 • 10/02/05 1258 1391 0 LAX 184 337 328 144 JFK 802 SFO PVD 187 1846 2467 BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm (cont) 371 2704 ORD 849 740 621 1464 1235 DFW 1423 2342 BWI 1090 946 1121 3288 2658 10/02/05 1258 1391 0 LAX 184 337 328 144 JFK 802 SFO PVD 187 1846 2467 BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm (cont) 371 2704 ORD 849 740 621 1464 1235 DFW 1423 2342 BWI 1090 946 1121 2658 10/02/05 1258 1391 0 LAX 184 337 328 144 JFK 802 SFO PVD 187 1846 2467 BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
Dijkstra’s algorithm (cont) 371 2704 ORD 849 740 621 1464 1235 DFW 1423 2342 BWI 1090 946 1121 2658 10/02/05 1258 1391 0 LAX 184 337 328 144 JFK 802 SFO PVD 187 1846 2467 BOS 867 621 MIA 946 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10/02/05
- Dijkstra algorithm graph theory
- Shortest path from source to destination in weighted graph
- Tracing dijkstra's algorithm
- Sssp
- Algorithm definition
- All-pairs shortest paths
- Prim's algorithm
- Shortest path linear programming
- Single-source shortest paths
- Difference constraints and shortest paths
- Shortest paths and transitive closure in data structure
- Weighted codes examples
- Cyclomatic