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

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

View Full Document Right Arrow Icon
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 !
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Consider any two distinct vertices x , y in G. • If (
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online