COMP 251B 2011, Assignment 4 Due Friday April 8th 2011
Problems 26-1: Escape problem
An n × n grid is an undirected graph consisting of n ro ws and n columns of vertices, as sho wn in Figure 26.11. We denote the vertex in the ith ro w and the jth column by (i, j). All vertices in a grid have exactly four neighbors, except for the boundary vertices, which are the points (i, j) for which i = 1, i = n, j = 1, or j = n. .
Figure 26.11: Grids for the escape problem. Starting points are black, and other grid vertices are white. (a) A grid with an escape, shown by shaded paths. (b) A grid with no escape. .
Given m ≤ n2 starting points (x 1, y1), (x 2, y2), . . . ,(x m, ym) in the grid, the escape problem is to determine whether or not there are m vertex-disjoint paths from the starting points to any m different points on the boundary. For example, the grid in Figure 26.11(a) has an escape, but the grid in Figure 26.11(b) does not.
a)
Consider a flo w net work in which vertices, as well as edges, have capacities. That is, the total positive flo w entering any given vertex is subject to a capacity constraint. Show that determining the maximum flow in a net work with edge and vertex capacities can be reduced to an ordinary maximum-flo w problem on a flow net work of comparable size.
b)
Describe an efficient algorithm to solve the escape problem, and analyze its running time.
Problems 21-1: Off-line minimum
The off-line minimum problem asks us to maintain a dynamic set T of elements from the domain {1, 2, ..., n} under the operations INSERT and EXTRACT-MIN. We are given a sequence S of n INSERT and m EXTRACT-MIN calls, where each key in {1, 2, ..., n} is inserted exactly once. We wish to determine which key is returned by each EXTRACTMIN call. Specifically, we wish to fill in an array extracted[1 ‥ m], where for i = 1, 2, ..., m, extracted[i] is the key returned by the ith EXTRACT-MIN call. The problem is "off-line" in the sense that we are allowed to process the entire sequence S before determining any of the returned keys.
A) In the following instance of the off-line minimum problem, each INSERT is represented by a number and each EXTRACT-MIN is represented by the letter E: 4, 8, E, 3, E, 9, 2, 6, E, E, E, 1, 7, E, 5. Fill in the correct values in the extracted array.
To develop an algorithm for this problem, we break the sequence S into homogeneous subsequences. That is, we represent S by I1, E, I2, E, I3, ..., Im, E, Im+1, w here each E represents a single EXTRACT-MIN call and each Ij represents a (possibly empty) sequence of INSERT calls. For each subsequence Ij, we initially place the keys inserted by these operations into a set Kj , which is empty if Ij is empty. We then do the following. OFF-LINE-MINIMUM(m, n) 1 for i ← 1 to n 2 do determine j such that i Œ Kj 3 if j ≠ m + 1 4 then extracted[j] ← i 5 let l be the smallest value greater than j for which set Kl exists 6 Kl ← Kj » Kl, destroying Kj 7 return extracted
B) Argue that the array extracted returned by OFF-LINE-MINIMUM is correct. C) Describe ho w to implement OFF-LINE-MINIMUM efficiently with a disjoint-set data
structure. Give a tight bound on the worst-case running time of your implementation.
Problem 23-4: Alternative minimum-spanning-tree algorithms
In this problem, we give pseudocode for three different algorithms. Each one takes a graph as input and returns a set of edges T. For each algorithm, you must either prove that T is a minimum spanning tree or prove that T is not a minimum spanning tree. Also describe the most efficient implementation of each algorithm, whether or not it computes a minimum spanning tree.
MAYBE-MST-A(G, w) 1 sort the edges into nonincreasing order of edge weights w 2 T←E 3 for each edge e, taken in nonincreasing order by weight 4 do if T - {e} is a connected graph 5 then T ← T - e 6 return T
MAYBE-MST-B(G, w) 1 T←Ø 2 for each edge e, taken in arbitrary order 3 do if T U {e} has no cycles 4 then T ← T U e 5 return T
MAYBE-MST-C(G, w) 1 T←Ø 2 for each edge e, taken in arbitrary order 3 do T ← T U {e} 4 if T has a cycle c 5 then let e′ be the maximum-weight edge on c 6 T ← T - {e′} 7 return T