CS330 Introduction to Algorithms November 26, 2012 All-pairs shortest paths, ows

advertisement
CS330 Introduction to Algorithms
November 26, 2012
All-pairs shortest paths, ows
1. Run the slow and fast all-pairs shortest paths algorithms on the graph dened by
the adjacency list below.
1 : 2 : 3 → 3 : 8 → 5 : −4
2:4:1→5:7
3:2:4
4 : 1 : 2 → 3 : −5
5:4:6
2. Describe how the Extend-Shortest-Paths algorithm corresponds to the Bellman-Ford
algorithm.
3. Let us assume that a graph G has nodes V = {1, 2, 3 . . . , n}. The Floyd-Warshall
algorithm is an iterative algorithm, that in iteration k produces all-pairs shortest
paths that only have nodes 1, 2, 3 . . . , k as intermediate nodes along the paths. Write
the recursive formula for computing the length of the shortest paths in iteration k .
Apply the algorithm to the graph in exercise 1.
4. Describe a naive way to use the Floyd-Warshall algorithm to compute the transitive
closure of a graph. Since you don't need to remember the length of the paths you
can substitute some operations with the logical AND and OR operations. Explain
how this goes.
5. Draw the auxiliary graph corresponding to the graph in exercise 1 used by Johnson's
algorithm. Where in the run of Johnson's algorithm do you need to use the BellmanFord and Dijkstra algorithms? Why do you need both? In what situation should
you use Johnson's algorithm?
6. Find the maximum ow from node s to t in the following graph. What is the
minimum cut?
s : v1 : 16 → v2 : 13
v1 : v3 : 12
v2 : v1 : 4 → v4 : 14
v3 : v2 : 9 → t : 20
v4 : v3 : 7 → t : 4
t:
7. How did you nd the augmenting paths in the previous algorithm? How does the
Edmonds-Karp algorithm nd them? What is the running time then for EdmondsKarp?
8. Given an unweighted directed graph G(V, E), with two special nodes s, t ∈ V , how
can you apply the max-ow algorithm to nd out the number of dosjoint paths
between s and t?
Download