**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