Lecture 7 All-Pairs Shortest Paths
All-Pairs Shortest Paths
Path Counting Problem
Adjacency Matrix
1 3 2 1 2 3 1 2 3
Theorem Proof. We prove it by induction on k.
k=1 True! 1 3 2 1 2 3 1 2 3
Induction Step
All-Pairs Shortest Paths with at most k edges
Recursive formula Proof.
Case 1. The path with length contains at most edges. Case 2. the path with length contains exactly edges.
Key Observation
Dynamic Program
Speed Up dynamic Program
Idea
Weighted Adjacency Matrix
1 4 5 6 3 2 1 2 3 1 2 3
A New Multiplication
Associative Law
Theorem Proof. We prove it by induction on k.
1 k=1 True! 4 5 6 3 2 1 2 3 1 2 3
Induction Step
All-Pairs Shortest Paths Theorem Proof
How to Compute
Lemma
Theorem
Theorem
Floyd-Warshall Algorithm
Observation
Dynamic Program
Theorem
Theorem
What we learnt in this lecture? The relationship between shortest path and matrix multiplication. Faster-All-Pairs-Shortest-Paths algorithm Floyd-Warshall algorithm.
Puzzle 1
Puzzle 2
Puzzle 3