230 likes | 570 Views
Comp 750, Fall 2009. All-pairs SPs - 2. ?Repeated Squaring" Algorithm. A dynamic-programming algorithm.Assume input graph is given by an adjacency matrix.W = (wij)Let dij(m) = minimum weight of any path from vertex i to vertex j, containing at most m edges.dij(0) =dij
E N D
1. Comp 750, Fall 2009 All-pairs SPs - 1 Chapter 25: All-Pairs Shortest Paths
2. Comp 750, Fall 2009 All-pairs SPs - 2 Repeated Squaring Algorithm
3. Comp 750, Fall 2009 All-pairs SPs - 3 Repeated Squaring (Continued)
4. Comp 750, Fall 2009 All-pairs SPs - 4 Repeated Squaring and Matrix Mult.
5. Comp 750, Fall 2009 All-pairs SPs - 5 Improving the Running Time
6. Comp 750, Fall 2009 All-pairs SPs - 6 Floyd-Warshall Algorithm
7. Comp 750, Fall 2009 All-pairs SPs - 7 FW (Continued)
8. Comp 750, Fall 2009 All-pairs SPs - 8 Predecessor Matrix
9. Comp 750, Fall 2009 All-pairs SPs - 9 Transitive Closure
10. Comp 750, Fall 2009 All-pairs SPs - 10 Example
11. Comp 750, Fall 2009 All-pairs SPs - 11 Another O(V3) T.C. Algorithm
12. Comp 750, Fall 2009 All-pairs SPs - 12 Code
13. Comp 750, Fall 2009 All-pairs SPs - 13 Johnsons Algorithm An O(V2 lg V + VE) algorithm.
Good for sparse graphs.
Uses Dijkstra and Bellman-Ford as subroutines.
Basic Idea: Reweight edges to be nonnegative. Then, run Dijkstras algorithm once per vertex.
Use Bellman-Ford to compute new edge weights w.
Must have:
For all u and v, a SP from u to v using w is also a SP form u to v using w.
For all u and v, w(u,v) is nonnegative.
14. Comp 750, Fall 2009 All-pairs SPs - 14 A General Result about Reweighting
15. Comp 750, Fall 2009 All-pairs SPs - 15 Proof of (ii)
16. Comp 750, Fall 2009 All-pairs SPs - 16 Reweighting in Johnsons Algorithm
17. Comp 750, Fall 2009 All-pairs SPs - 17 Code for Johnsons Algorithm
18. Comp 750, Fall 2009 All-pairs SPs - 18 Example
19. Comp 750, Fall 2009 All-pairs SPs - 19 Example
20. Comp 750, Fall 2009 All-pairs SPs - 20 Example
21. Comp 750, Fall 2009 All-pairs SPs - 21 Example
22. Comp 750, Fall 2009 All-pairs SPs - 22 Example