lecture_12

# lecture_12 - All-pairs shortest paths Input a weighted...

This preview shows pages 1–7. Sign up to view the full content.

All-pairs shortest paths Input: s a weighted directed graph G = (V,E) s edge weight w(e) can be +ve or –ve ; To find: s the shortest (smallest weight) path between all pairs of vertices. Assumption: G has no negative cycles. Using Bellman-Ford algorithm, we can find the shortest path from a fixed vertex to every other vertices in O(n m) time. All-pairs shortest paths: O(n 2 m) time . O(n 3 ) time !

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Path property Assume that G has no negative cycles. Suppose there is a path from vertex x to vertex y . Then there exists a path from x to y that is a simple path (no duplicate vertexes), containing at most n edges. u v weight of cycle 0
Warshall’s Algorithm Warshall’s Algorithm - O(n O(n O(n 3 ) time Assume G contains n vertices, labelled from 1 to n . Consider any vertices x , y . For any integer k [ 0 , n], an inter- k path from x to y is a path on which every intermediate vertex has label k . efine ist , y, = the smallest possible weight of an Define dist (x, y, k ) = the smallest possible weight of an inter- k path from x to y. If no such path, let dist (x, y, k ) = ∞. x y k k k k k NB. k is not a measure of the length of path; it is the maximum intermediate label on the path.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example Example Definition. dist (x, y, k ) = the smallest possible weight of an inter- k path from x to y. dist(1, 4, 0) = ∞ dist(1, 4, 1) = ∞ 1 5 4 6 1 -2 3 2 3 dist(1, 4, 2) = ∞ dist(1, 4, 3) = ∞ dist(1, 4, 4) = ∞ dist(1, 4, 5) = 4 dist(1, 4, 6) = 1 dist(5, 6, 0) = 3 2
Consider any two distinct vertices x , y in G. • If ( x, y ) is an edge, then dist( x, y , 0) = w(e); otherwise dist(x, y, 0) = ∞. • If x is connected to y then dist( x, y , n) = the shortest istance from x to y is equal to dist( , y n). Warm Up distance from x to y is equal to dist( x, y , n). x y n n n n n

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Consider any two distinct vertices x , y in G. • If (
This is the end of the preview. Sign up to access the rest of the document.
• Spring '10
• Chan
• Shortest path problem, Gospel of John, Saint Peter, Proof by contradiction, Amy Jane, John Peter Jack Mary Mary Amy Jane Amy Jane Least

{[ snackBarMessage ]}

### Page1 / 24

lecture_12 - All-pairs shortest paths Input a weighted...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online