Docsity

Algorithm Design and Analysis - Problem Set 4 Solutions | ECS 122A, Assignments of Computer Science

Toggle sidebar
bg1
ECS 122A: Algorithm Design and Analysis Homework 4
UC Davis: Charles Martel, Susan Margulies Due Monday, May 19, 2008, 4:00 PM
Problem Set 4
1 Max Flow, KT: 7.1,7.2 (25 pts)
i) An arc is upward critical if increasing the capacity of the arc increases the maximum flow
value. Does every network have an upward critical arc?
Solution: No. Not all networks have an upward (or for that matter downward) critical arc.
Consider a simple network with:
s—> a—> b—> t
and all arcs have capacity 2. The max flow is 2 unless we increase the capacity of all three
arcs, so no single arc can increase the max-flow by increasing its capacity only.
ii) Describe an algorithm to efficiently find all upward critical arcs in the network.
Solution: To find all upward critical arcs, first find a max flow f. An upward critical arc
(u, v) has the property that increasing its capacity will increase the max flow. Thus the
residual graph Gfwould gain an augmenting path if we change the capacity of the edge
(u, v). This can only happen if:
1. The edge (u, v) is saturated (so increasing its capacity will change Gf), and
2. There is a path from sto uand from vto tin Gf.
If both these conditions hold, (u, v) is upward critical. Otherwise, it is not upward critical
(since we can see that if we increase the capacity, there is still no augmenting path in Gf).
We can find all vertices ureachable from sin Gfby a BFS, and if we reverse all the arcs in
Gfand do a BFS from twe find all vetices vwhich can reach t. Now it is simple to check
each arc in G to see if i) and ii) apply. Thus once we have a max flow we can find all upward
critical arcs in O(m) (additional) time.
iii) A arc is downward critical if decreasing its capacity reduces the max flow value. Are the
downward and upward critical arcs the same? Justify your answer.
Solution: No. Downward and upward critical edges are not always the same. An upward
critical edge is always downward critical because it is part of a min-cut, and thus decreasing
its capacity reduces the capacity of the min-cut.
In the example under a) above, each of the three arcs are downward critical (reduce any of
them to one and the flow drops to one).
2 Max Flow, KT: 7.1,7.2 (25 pts)
Suppose that in addition to each arc having a capacity, we also have a capacity on each node (thus,
if node ihas capacity ci, then the maximum total flow which can enter or leave the node is ci).
Suppose you are given a flow network with capacities on both arcs and nodes. Describe how to find
pf3
pf4
pf5

Partial preview of the text

Download Algorithm Design and Analysis - Problem Set 4 Solutions | ECS 122A and more Assignments Computer Science in PDF only on Docsity!

ECS 122A: Algorithm Design and Analysis Homework 4 UC Davis: Charles Martel, Susan Margulies Due Monday, May 19, 2008, 4:00 PM

Problem Set 4

1 Max Flow, KT: 7.1,7.2 (25 pts)

i) An arc is upward critical if increasing the capacity of the arc increases the maximum flow value. Does every network have an upward critical arc? Solution: No. Not all networks have an upward (or for that matter downward) critical arc. Consider a simple network with: s—> a—> b—> t and all arcs have capacity 2. The max flow is 2 unless we increase the capacity of all three arcs, so no single arc can increase the max-flow by increasing its capacity only.

ii) Describe an algorithm to efficiently find all upward critical arcs in the network. Solution: To find all upward critical arcs, first find a max flow f. An upward critical arc (u, v) has the property that increasing its capacity will increase the max flow. Thus the residual graph Gf would gain an augmenting path if we change the capacity of the edge (u, v). This can only happen if:

  1. The edge (u, v) is saturated (so increasing its capacity will change Gf ), and
  2. There is a path from s to u and from v to t in Gf.

If both these conditions hold, (u, v) is upward critical. Otherwise, it is not upward critical (since we can see that if we increase the capacity, there is still no augmenting path in Gf ). We can find all vertices u reachable from s in Gf by a BFS, and if we reverse all the arcs in Gf and do a BFS from t we find all vetices v which can reach t. Now it is simple to check each arc in G to see if i) and ii) apply. Thus once we have a max flow we can find all upward critical arcs in O(m) (additional) time.

iii) A arc is downward critical if decreasing its capacity reduces the max flow value. Are the downward and upward critical arcs the same? Justify your answer. Solution: No. Downward and upward critical edges are not always the same. An upward critical edge is always downward critical because it is part of a min-cut, and thus decreasing its capacity reduces the capacity of the min-cut. In the example under a) above, each of the three arcs are downward critical (reduce any of them to one and the flow drops to one).

2 Max Flow, KT: 7.1,7.2 (25 pts)

Suppose that in addition to each arc having a capacity, we also have a capacity on each node (thus, if node i has capacity ci, then the maximum total flow which can enter or leave the node is ci). Suppose you are given a flow network with capacities on both arcs and nodes. Describe how to find

a maximum flow in such a network (Hint: by modifying the network you can use a standard flow algorithm to solve this problem).

Solution: In order to find the maximum flow in a network where nodes as well as edges have an associated capacity, simply break each node i into 2 separate nodes i′^ and i′′^ and connect them with an edge with capacity ni (where ni is the capacity of the given node). Connect all incoming edges to node i′^ and all outgoing edges leave node i′′. Then run the maximum flow algorithm on that new network.

3 Max Flow, KT: 7.1,7.2 (25 pts)

Use network flows to solve each of the following problems:

a) You are given a directed, strongly connected graph. Each arc has a cost associated with it. We want to find a minimum cost set of arcs such that removing that set of arcs makes the graph no longer strongly connected. Solution: Our algorithm is as follows:

  1. To solve this problem treat the graph as a flow network where each arc has capacity equal to its cost (source, sink to be specified later). A simple solution is to take each pair of vertices u, v in the network and find the min-cut between them treating one as the source and the other as the sink. This takes n^2 − n flows. A better solution is: Connect a source s to vertex 1 with an edge of infinity capacity (or capacity greater then the sum of capacities on every edge), and one by one, connect a sink t to (2, 3 ,... , n) using an edge of infinite capacity, and find the minimum cut for each network. Then connect a sink t to vertex 1 using an edge of infinite capacity and one by one, connect a source s to (n, n − 1 , n − 2 ,... , 2), again using an edge of infinite capacity. Find the minimum cut for each of these 2n − 1 networks, and then find the minimum minimum cut over all the networks.
  2. The capacity of that minimum minimum cut is minimum weight set of edges needed to disconnect the graph.

We structure our proof of correctness as follows. First, we argue that by varying the source and the sink in the pattern specified above, we actually enumerate all

(n 2

possible source-sink combinations, and therefore all of the possible minimum cuts. Thus the minimum minimum cut as found above is acutally the minimum possible cut in the graph. Then we argue that we must remove all of the edges on a minimum minimum cut in order to disconnect the graph.

  • Claim: By fixing a source to vertex 1, and varying the sink over the other n − 1 nodes, then fixing a sink to 1 and varying the source over the other n − 1 nodes, we actually enumerate all of the

(n 2

possible source-sink combinations, and therefore, the minimum of the minimum cuts calculated by the above source-sink pattern is the minimum cut over all possible cuts in the graph.

  • Proof by contradiction: Suppose there exists a source-sink combination (i, j), where i is the source and j is the sink, and suppose that the minimum cut found in this network

c) Same as b) but find the minimum number of days to test all lines (and a schedule which achieves it). Solution: In order to find the minimum number of days needed to test all of the lines, we run the max flow algorithm in the following fashion:

  1. Let k = 1.
  2. Construct the graph as specified above with edge (s, Pi) having capacity k · ti.
  3. Run the max flow algorithm. a. If the flow is m (all tested), find which processors can test which lines and return k.
    1. If not all lines are reachable, then let k = k + 1 and repeat from step 2.

When our algorithm returns, we only know that Pi can test a given set of lines, but we don’t know in which order. However, the order is irrelevant. As long as Pi tests only those particular lines, ti per day, than the solution will be optimal. This algorithm is O(mV 3 ), because it would take at most m days to test all m lines. Smarter would be to use binary search or use the flow for k days as the initial flow for k + 1 days. Also note that a simple greedy algorithm that finds a max flow for one day, removes those lines, and then reruns on the remaining lines, repeating until all tested, does not work.

4 Hashing, KT: 13.6 (25 pts)

Problem 11-2.3 on page 229, CLRS. Professor Marley hypothesizes that substantial performance gains can be obtained if we modify the chaining scheme so that each list is kept in sorted order. How does the professor’s modification affect the running time for successful searches, unsuccessful searches, insertations and deletions. First briefly describe how you would do insertions and deletions to maintain a sorted list, and how you would now do searches. Then analyze the performance.

Solution: Given that we expect any average hash to take 1 + α, where α < 1, our “substantial performance gains” must be in terms of a constant reduction, because we can not improve asymp- totically on a constant time function. To determine if we have the desired reduction, we should investigate the expected running time changes for each of the listed operations. Note that given linked lists, we can not employ a binary search, as we would otherwise like.

successful searches: If we look up every item, the total lookup time is exactly the same regardless of the order in the chain. Thus in either the sorted or unsorted chains we expect the average time to discover an existing item to be 1 + α/2.

unsuccessful search: In this case, sorted chains allow us to give up earlier because once we reach a number higher than our key, we can quit looking. Meanwhile, for unsorted lists, we must look at every item before deciding the key does not exist. Thus we have 1 + α/2 verses 1 + α for sorted verses unsorted, respectively (this assumes each item is equally likely to be in the table or looked up unsuccessfully).

insertions: As given in class, an insertion is composed of first a search for a key, followed by adding the key if it does not already exist or no operation if it does. For this problem let us assume that the large majority of insertions involve keys that are not yet in our hash table. In that case, an

insertion is an unsuccessful search followed by a constant order list addition. Thus, the comparitive running times are 1 + α/2 verses 1 + α, as above (though note that here the value α is varying as we insert).

deletions: Assuming that the keys we are deleting exist in our table, we have a successful search followed by a constant time operation. As with successful searches, the comparative running times are both 1 + α/2.

Overall, the improvements are rather meager. If we had an equal mix of all the listed operations, the new average hash time would be 1 + α/2 when compared to unsorted chaining. If we expected many unsuccessful searches, we would get the most benefit.