CSC373 Assignment 1 Solutions Spring 2012
CSC373 Assignment 1 Solutions Spring 2012
1. Communications network. 1a) Prove that P A is in NP. PA(G,U,P,k) is clearly a decision problem. Set the input string s to describe the input (G, U, P, k), where G = (V, E), and P is the set of simple paths P = {Pu |u U }. Since each simple path Pu has no more than |V | 1 edges, we take the size of the encoding of P to be bounded by |V ||U |. Similarly, we assume we can encode E using size O(|V |2 ). We therefore dene |s| = O(|V |(|V | + |U |)). For s P A we dene the certicate t to specify a subset of users S U with |S| = k, such that for every distinct pair u, w S the associated paths Pu and Pw do not include a common vertex. By the denition of the problem, such a t exists i s P A. The size of |t| is dened to be |S| = k |U |, which is O(|s|). The certier algorithm C(s, t) is dened to return true i s and t have the above form. That is the k paths selected by t are items in P , and no pair of these paths share a common vertex. For each pair of paths this verication requires at most O(|V |2 ) time. So C(s, t) runs in time O(k 2 |V |2 ) (|s|4 ). It follows that C(s, t) is a poly-time certier for problem P A. Therefore, P A is in NP. 1b) Prove that P A is NP-complete by using a polynomial reduction from the the 3-Dimensional Matching problem (3DM). From part (a) and the NP-completeness of 3DM we only need to show 3DM p P A. An instance of three dimensional matching, say 3DM (X, Y, Z, T, k), involves the three disjoint sets X, Y , and Z, a non-negative integer k, and the set of m triples T = {tj = (x(j) , y(j) , z(j) ) | 1 j m, x(j) X, y(j) Y, z(j) Z}. The problem is to decide whether there exists a subset S T , with |S| = k, such that no two triples in S share the same value of x X, y Y , or z Z. Let the string s specify such a 3DM problem. We dene |s| = |X| + |Y | + |Z| + |T |. The reduction to PA proceeds as follows. Let U be a set of users in 1-1 correspondence with the triples in T . We dene the communication network graph G = (V, E) with V = X Y Z. We take E to be all possible undirected edges between these vertices. For each triple t = (xt , yt , zt ) T we dene the associated path Pt to be (xt , yt , zt ) in G (i.e., a simple path two edges in length). Finally, we dene P to be the set of all such paths Pt for t T . We use the same k for both problems. It follows that this whole construction can be done in O(|s|2 ) time. This polytime construction is followed by the single call to P A(G, U, P, k). The key claim is that 3DM (X, Y, Z, T, k) is true i P A(G, U, P, k) is true for the constructed path allocation problem. This follows from the 1-1 correspondence between triples and paths, along with the direct correspondence between the intersection of two triples with the intersection of the constructed paths. We omit the details. It follows that 3DM p P A. 1c) Use a polynomial reduction from the Independent Set problem. We need to show IS p P A. Let G = (V, E) and k specify an instance of the independent set problemIS(G, k). Suppose the string s denotes V, E and k, and dene |s| = |V | + |E|.
We form the communication network graph H = (W, F ) for a path allocation problem as follows. The set of vertices W of H is dened to be W = {we | e E} {wv,1 , wv,2 | v V }. That is, there are two distinct vertices in W for each vertex v V , and one unique vertex for every edge in e E. The set of edges F in graph H is taken to be full. We can construct graph H in time O(|s|2 ). Dene the set of users to be U = V . Finally, the path Pv for any user v U is dened to be a simple path connecting the set of vertices Wv (in any order), where Wv = {wv,1 , wv,2 } {we | e E with one endpoint equal to v}. Note, with the addition of the vertices wv,1 , wv,2 , each of these paths has at least one edge, as required by P A. Constructing the set of paths P requires O(|V |2 ) time (since there are |V | paths, each of which passes through no more than |Wv | = O(|V |) vertices). We use the same k for both problems. Therefore this construction of the problem P A((W, F ), U, P, k) requires O(|s|2 ) time. With this construction we claim that IS((V, E), k) is true i P A((W, F ), U, P, k) is true. The reason for this is, by construction, two paths Pv and Pu do not share a vertex i u and v are not connected by an edge in E. We omit the details. It follows that IS((V, E), k) is true i P A((W, F ), U, P, k) is true for this constructed instance of P A. Therefore IS p P A. 1d) Show that Allocate(G, U, P ) polynomially reduces to P A(G, U, P, k). Suppose we are given the input G, U, P for an instance of Allocate(G, U, P ). We dene the string s to represent G, U, P and |s| = O(|V |(|V | + |U |)), as in part (a) above. To show Allocate p P A we will construct a suitable subset of paths S using polytime operations plus polynomially many calls to P A. Step 0: Use bisection on P A(G, U, P, k), for k between 1 and |U | = |P |, to nd the largest k for which P A(G, U, P, k ) is true. This requires O(log(|U |)) O(log(|s|)). Next initialize S, the set of users selected so far to be empty, and assign k to be k . Initialize the current set of users and paths to be Wk = U and Qk = P , respectively. If k > 0 perform the following steps: Step 1: Initialize W = Uk and Q = Qk . Then, for each user u W , successively set W W \{u} and Q Q\{Pu }. If P A(G, W, Q, k) is true continue this loop, otherwise remember u, W , Q and break out. This loop must break out at some point, say at least when |Q| < k. We now have u Uk , W Uk and Q Qk such that P A(G, W, Q, k) is false, but P A(G, W {u}, Q {Pu }, k) is true. (Intuitively, this suggest we can take u to be in S.) Step 2: Set S S {u}. For each user w W , if the path Pw shares a vertex with Pu then remove user w from W and remove the path Pw from Q. Step 3: After completing Step 2, let Wk1 = W and Qk1 = Q. We claim that P A(G, Wk1 , Qk1 , k 1) is true. (Use contradiction.) Step 4: Set k k 1. If k > 0 repeat steps 1 through 4. It follows that Steps 1 throung 4 can be repeated k times, and the above procedure forms a set of users S with size |S| = k (details omitted). We also claim that this set of users S is an appropriate solution for the search problem Allocate(G, U, P ) (details omitted). This construction of S takes at most O(|U |) O(|s|) calls to the black box P A solver. The whole process therefore runs in poly-time in |s| plus O(|s|) calls to the P A solver. Therefore Allocate p P A. 2
1e) Prove Professor Jots greedy algorithm is incorrect. The reduction of IS((V, E), k) to P A in part (c) uses a 1-1 correspondence between users U and vertices V . Moreover, by construction, two paths Pu and Pv share a vertex i (u, v) is an edge in E. Moreover, it follows that the conict size c(u) for any user u is equal to the degree of the corresponding vertex u in the original graph G. Therefore, we can interpret Prof. Jots algorithm, on such a constructed problem, as the following equivalent algorithm on the original graph G = (V, E). Algorithm IS-Jot: [S] = MaxIndSet(V, E) Initialize R V and S { }. Sort the vertices R in increasing order of their vertex degree in the original graph G = (V, E). Say this sorting results in R = [r1 , r2 , ...rn ]. For k = 1, . . . , n. Check if, for any j < k, rj S and (rj , rk ) E. If not, then set S S {rk }. End for return S
Claim: If we can show that algorithm IS-Jot does not work for IS(G) then it follows that Prof. Jots algorithm will not work on the corresponding PA problem. Proof Sketch: Consider Prof. Jots algorithm applied to a P A problem constructed as above from a given Independent Set problem for G = (V, E) and k. Then, due to the 1-1 relationships noted above, for such a P A problem we can view Prof. Jots algorithm as an equivalent algorithm for the independent set problem IS((V, E)). This completes the proof sketch for the previous claim. We are now left with showing that the above algorithm does not work for IS. Consider the graph G = (V, E) illustrated below.
The minimum degree is 3, and multiple vertices have degree 3. Algorithm IS-Jot can start at any one of these vertices. If it starts at the light blue (light grey) vertex on the left side, then the maximum size of any independent set which contains this vertex is seen to be two. (For example, include the light blue (light grey) vertex on the right.) This would be a possible output of Prof. Jots algorithm. However, the red (darker grey) vertices illustrate an independent set of size 3. Therefore Prof. Jots algorithm is not correct. (Perhaps only depending on how it breaks ties, but nevertheless incorrect.) 2. Degree12Tree is NP-complete. Optional (Students may assume Degree12T ree(G) is in NP, although we show that here.): Degree12T ree(G) (or D12T for short) is a decision problem. Moreover, suppose the input string s denes G, with |s| = |V | + |E|. Dene the certicate t to describe a spanning tree T = (V, F ) of G with degree 12. Such a certier exists i s D12T . Moreover, |t| = |V | + |F | = O(|s|), and the conditions on t can be checked in O(|s|) time (say by doing a modied breadth rst search on T to verify T spans V and T is acyclic). Therefore there exists a polytime certier for the decision problem Degree12T ree, hence it is in N P . 3
We will use the undirected Hamiltonian Cycle problem (uHC) (p.479 of the text). (Students can also use the undirected Hamiltonian path (uHP) problem if they wish.) We wish to show uHC(G) p D12T (G). Given an instance of uHC(G), let string s dene the undirected graph G = (V, E) (with |s| = |V | + |E|). We rst construct a small modication of G, namely G , and then use this new graph G to form the input for the D12T problem. (An example of this construction is illustrated in the gure below.) Select a vertex v V (let me ignore the case G is empty), and form V = (V \{v}) {v0 , v1 , v2 , v3 }. Dene G = (V , E ) with the edges E given by E ={(u, w) | (u, w) E, with u = v and w = v} {(u, vk ) | (u, v) E, k = 0 or k = 3} {(v0 , v1 ), (v2 , v3 )}
Claim 1. G = (V , E ) has a (undirected) Hamiltonian path P i G = (V, E) has a Hamiltonian cycle C. Moreover this P , when it exists, must have the endpoints v1 and v2 . Pf: Briey, note that if G has a Hamiltonian cycle C, then it must pass through v. Consider the resulting path P of length |V | from v to v. Construct the simple path P in G by replacing the two endpoints v of P by v0 and v3 , and then adding the two edges (v0 , v1 ), and (v2 , v3 ) to either end. Then it follows that the resulting path P is a simple path in G which includes every vertex in V . Therefore P is a Hamiltonian path in G (with endpoints v1 and v2 ). Conversely, suppose P is a Hamiltonian path in G . Then it must contain the vertices v1 and v2 . Since these vertices have degree 1, they must be the endpoints of P . Therefore, by the construction of G , P is a simple path of the form (v1 , v0 , u1 , . . . , un , v3 , v2 ) (or the reverse). Here uk for k = 1, . . . , n must include every vertex in V \{v} exactly once (since P is Hamiltonian). It follows that (v, u1 , . . . , un , v) is a Hamiltonian cycle in G. This completes the proof of Claim 1. Next we construct a undirected graph H = (W, F ) for the D12T problem from this modied graph G = (V , E ). For every vertex u V , add 10 additional vertices {wk (u) | k = 1, . . . , 10}, along with the edges (u, wk (u)), k = 1, . . . , 10. These single edges are the only edges to these additional vertices wk (u). Eectively u is the root of a subtree of height one, which consists of the vertex u and these 10 new vertices wk (u), k = 1, . . . , 10. Dene W = V {wk (u) | 1 k 10, and u V } Dene the set of edges F in the graph H = (W, F ) to be F = E {(u, wk (u)) | 1 k 10, and u V }. This construction of H from the original graph G requires O(|V | + |E|) = O(|s|) time. Claim 2. For this construction, D12T (H) is true i uHC(G) is true. Notice that the desired reductino, namely uHC p D12T , will follow from Claim 2 since the construction of H is polytime, and we require only one call to D12T (H). 4
Proof of Claim 2. Assume uHC(G) is true, and C is a Hamiltonian cycle. Then by Claim 1 there must exists a Hamiltonian path P of G with endpoints v1 and v2 . Therefore P is a spanning tree of G with degree at most 2. Note that this implies P has exactly |V | 1 edges. Finally, the subgraph formed from the vertices and edges in P can be extended to a subgraph T = (W, ET ) of H by including in ET the 10|V | additional edges (u, wk (u)) for each u V and each k = 1, . . . , 10. By construction, the addition of these extra edges implies T has at most degree 12 (since P has at most degree 2). The number of edges in T is the sum of |V | 1 (i.e., the number of edges in P ) plus the added edges 10|V |. That is, |ET | = 11|V | 1. The number of vertices in T is |V | + 10|V | = 11|V |. Moreover, since every vertex wk (u) is connected to u V , and the path P spans V , we conclude that T must be connected. Therefore T = (W, ET ) is a connected graph with |ET | = |W | 1 edges. So T must be a spanning tree of H. Therefore D12T (H) must be true. Conversely, suppose D12T (H) is true. Let T be any spanning tree of H of degree less than or equal to 12. Since T is a spanning tree, there must be a simple path Q in T between vertices v1 and v2 . This path cannot contain any of the leaf vertices wk (u) (since they each have only one incident edge and they are distinct from v1 and v2 ). Therefore Q must be a simple path connecting v1 and v2 in G . We claim Q is a Hamiltonian path in G . To show this we use contradiction to show that every vertex in V is on Q. The argument goes as follows. Suppose x V is not reachable from v1 on Q. Since T is a spanning tree, there is a unique a path R in T between v1 and x. Let the edge (a, b) be the rst edge on this path in T that deviates from Q. Since Q is dened to be the restriction of T to the vertices V , the edge (a, b) must not be between a pair of vertices in V (otherwise the edge would be in Q as well). That is, this edge (a, b) must have an endpoint that is not in V . Therefore a or b must be wk (u) for some k and u V . But such a vertex is degree one, and this contradicts R being a simple path between v1 and x V . Therefore any x V must be reachable on Q. So it follows that Q must be a Hamiltonian path in G . Finally, by Claim 1, it follows that G must have a Hamiltonian cycle. This completes the proof of Claim 2. 3. Prof. Jots Second Algorithm. [S] = MinTreeVertexCover(V, E) % Return a vertex cover of minimum possible size for % the input tree T = (V, E). % Precondition: T is a valid undirected tree Initialize F (V, E) and S { }. While the forest F is not empty: Find a leaf vertex u in F . If there is no edge in F which includes u as an endpoint: Delete u from F. Else: Let (u, v) be such an edge in F . Set S S {v}. Remove u, v, (u, v), and all other edges which include v from F . End if End while return S Fortunately for the prof. this time his algorithm is correct. Proof. First note that the algorithm terminates, since it removes either one or two vertices from W each
iteration, and W initially has the nite size |V |. The key idea is to prove that the algorithm is promising at each stage. That is, after k iterations (including k = 0, for the start case), we wish to prove that the following loop invariant is true. Loop Invariant L(k): Let F = (W, EF ) be the current forest in the algorithm, and S be the subset of vertices selected so far. Then there exists a minimum sized vertex cover C, of the original graph T = (V, E), such that S = C (V \W ). That is, S is promising. Moreover, the edges that have been removed so far, specically, edges in E\EF , all have at least one endpoint in S. Note that, the algorithm terminates on iteration k when the forest F is empty, and the correctness of the algorithm would follow from L(k ) for this last iteration. We are left with proving L(k) by induction, on k = 0, 1, . . . , k . The base case is k = 0. Note L(0) follows from the existence of a minimal cover C. Assume k is some non-negative integer and the algorithm has completed k iterations, and F is not empty. Moreover, assume L(k) is true. We need to prove L(k + 1). It is useful to dene W r = V \W , which is the set of vertices removed from V by the end of the k th iteration. Below, let C denote the optimal solution described in L(k), with C W r = S. Consider L(k + 1). Since there must be a leaf in a forest, one of the two conditions in the loop body must hold. First, suppose that u is an isolated vertex in F . By L(k), all the edges in the original set E that have an endpoint at u are already covered by vertices in S (their other endpoints must be in W r ). Therefore, u can be safely removed, preserving this edge covering property of S for all edges with on endpoint in W r {u}. Moreover, if C were to include the vertex u, then it can be shown that it could be removed without destroying the vertex cover property. This is impossible because C is assumed to be a minimal vertex cover. Therefore, with S remaining unchanged this iteration, we still have S = C (W r {u}). Therefore L(k + 1) is true in this case. Alternatively, suppose the conditions for the else clause are satised. That is, for the leaf u there exists a unique (because it is a leaf) edge (u, v) in EF which has u as its endpoint. It follows that any other edge (u, w) E must have w W r and L(k) ensures that this edge is already covered by S. Therefore it must be the case that w S C for all such edges (w, u) E with w = v . The edge (u, v) is therefore the only edge in E having u as an endpoint which is not covered already by S. Note that it must be covered by a vertex in C. Therefore C must contain either u or v. If v C, then L(k + 1) follows. Otherwise, as we argued above, we must have u C. Consider the set C = (C\{u}) {v} (which involves an exchange of u for v). We saw above that the vertices in C W r already cover all the edges in E ending at u, except for the one edge (u, v). Since C W r = C W r and v C , it follows that C covers all the edges in E ending at u. Similarly, since C contains v, it must cover all edges ending at v. These are the only two types of edges that can change coverage between C and C . So C must also be a vertex cover. Moreover, since it is the same size as C, it must be a minimal vertex cover. The statement L(k + 1) and the induction step now follow by using the minimum sized vertex cover C .