This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Lecture 17, Nov 30, 2010 Single-Source Shortest Paths Problem:
» » » » Directed graph G=(V,E), n nodes, m edges. Edge uv has (real) weight w(uv). Distinguished node s, the “source”. Need to find shortest paths from s to all nodes reachable from s. Encoding
» Easy if all we need are (n-1) distances » Encoding each path might take linear space per path, times n-1 paths -- Too much ! » We will show that the answer is a “shortest paths tree”. 199 Optimum substructure Main observation: if shortest path s to v goes through u, then its part up to u is the shortest path from s to u. s u v Why ? Cut-and-paste argument – replace green with red if red shorter. Note that if uv is a single edge (v is neighbor of u), the above claim is still true
200 1 Shortest paths trees Above claim implies that all we need is: “for every node v, remember the node u such that shortest path from s to v ends with uv edge” Results in a tree ! (Why? Can there be cycles?) Example of shortest path trees.
» Edge uv in tree if the shortest path from s to v is through u. » Not unique – both (b) and (c) are correct 201 Bellman-Ford We will use Dynamic Programming
» Greedy algorithm exists for special case of “non-negative weights” » Will be discussed next lecture Subproblem: dk(v) = distance from s to v in up to k “hops”. To reach v in at most k+1 hops:
» » » » » reach neighbor u of v in k hops, hop from u to v alternatively, reach v in at most k hops phase k computes dk(v) for all v. O(m) per phase s u v d k 1(v) min d k (v), min d k (u ) w(uv) | uv E Start with dk(v) =∞ for all nodes except source Think in terms of “receive updated distances from neighbors”
202 2 Termination We can terminate at phase k if, for all v, dk(v) = dk-1(v) , since no more changes will happen in dk(v) for larger values of k. Terminates in n-1 phases if no negative cycles (might terminate earlier)
» Proof in the textbook. » Main idea:
– dk(v) –distance to reach v in up to k hops. – dk(v) does not increase with k, decreased with each update – If for some k>n-1 it is updated, then dk(v)< dn-1(v) – If more than n-1 hops are used, then path is not simple – Implies a negative-cost cycle along this path s u v Total running time: O(nm) Total “extra space” (beyond the graph structure): O(n) Basis for RIP protocol
203 Bellman-Ford If negative cycle exists then no termination, even in n-1 phases: Proof:
– Consider edge vivi+1 along the cycle at termination. – If terminated, then for all edges vivi+1 on the cycle: d (vi 1) d (vi ) w (vivi 1)
– Sum up: weight of the cycle 0 d (vi 1) d (vi ) (weight of the cycle) i i What if cycle is unreachable from s ? 204 3 ...
View Full Document