Algorithm Design Techniques Assignment 3: Solutions (1) Hamiltonian Path. (a) Longest Path Problem The Longest Path Problem is in NP. Given a solution path P , we just check that P consists of at least k edges, and that these edges form a path (where no vertex is used more than once). This verification can be done in polynomial time. The reduction follows directly from Hamiltonian Path. Given an instance of Hamiltonian Path on a graph G = (V, E). We create an instance of the longest path problem G0 , k as follows. We use exactly the same graph, i.e G0 = G and we set k = |V | − 1. Then there exists a simple path of length k in G0 iff G0 contains a Hamiltonian path. (b) Minimum Leaf Spanning tree The Minimum Leaf Spanning tree is in NP. Clearly the certificate is a tree of k leaves, which can be verified in linear time. Again, the reduction follows directly from Hamiltonian Path. Given an instance of Hamiltonian Path on a graph G = (V, E). We create an instance of the minimum leaf spanning tree problem G0 , k as follows. Again, we use exactly the same graph, i.e G0 = G but now we set k = 2. A tree with 2 leaves is a path, so a spanning tree with two leaves is a Hamiltonian Path in the graph. So there exists a Hamiltonian path iff there exists a spanning tree with 2 leaves. (2) Hitting Set Problem. The Hitting Set problem is in NP. To check a solution a∗1 , . . . , a∗k we just see if every set Bj is hit by at least one of the a∗i . We use a reduction from Set Cover to show NP-completeness. Given sets S1 , . . . , Sn and a ground set W = {w1 , . . . , wm } of elements to cover, let a1 , . . . , an represent the sets and let B1 , . . . , Bm represent the elements. We say that ai hits Bj if and only if set Si contains element wj . It follows that 1 2 there is a hitting set of size at most k if and only if there is a set cover of size at most k. This is a polynomial reduction. We use a reduction from Partition to show NP-completeness. We have inteP P gers x1 , . . . , xn and we want to find a subset S ⊂ [n] with i∈S xi = i∈S / xi . To set this up as a zero-weight cycle problem we take a directed cycle with n arcs, one for each integer. We now make two copies of each arc i. One copy has weight xi and the other has weight −xi . So any directed cycle in G uses exactly one the type i arcs. Let S be the set of integers where we use their P P positive arcs. Thus the weight of the corresponding cycle is i∈S xi − i∈S / xi . Clearly, this equals zero if and only if we have the desired partition. This is a polynomial reduction. (3) Dominating Set. Dominating Set is in NP. To check a proposed solution S ⊂ V , we simply have to check that any vertex not in S is adjacent to some vertex in S. We use a reduction from Set Cover to show NP-completeness. Given sets S1 , . . . , Sn and a ground set W = {w1 , . . . , wm } of elements to cover, we create a graph as follows. There is a vertex vi for each set Si and a vertex uj for each element wj . There is an edge (vi , wj ) if and only if wj is in set Si . Finally we add an edge (vi , vi ) for each pair of sets Si and Sj - we do this because then every vi are more useful than any uj in building a dominating set. It is then easy to see that there is a dominating set of size at most k in G if and only if there is a set cover of size at most k. This is a polynomial reduction. (4) Feedback vertex set. The Feedback vertex set problem is in NP. To check a proposed solution, X ⊆ V , we just verify that G − X forms an acyclic graph. This verification can be done in polynomial time. We use a reduction from Vertex Cover problem to show NP-Completeness. Take an instance of vertex cover in an undirected graph GU = (V 0 , E 0 ). We now replace each edge in the undirected graph with two directed edges, a forward edge and a backward edge to obtain the directed graph, GD = (V 0 , A). So we now need to prove that, X ⊆ V is a vertex cover in GU iff X forms a feedback vertex set in GD . Assume X is a vertex cover of GU . Then by definition, every edge of GU must be incident with at least one vertex of X. Clearly, every directed edge 3 of GD should also be incident with at least one vertex of X. So every cycle in GD must include a vertex of X. Now, assume that X is a feedback vertex set of the directed graph GD . Then by definition, every cycle in GD must include a vertex of X. Consider any cycle of length 2. This is just a pair of directed edges between two vertices. So X must contain at least one vertex for each cycle of length 2 in GD . But, by our construction, for every edge in GU joining two vertices, GD contains a cycle of length 2 between the same pair of vertices. So X contains at least one of these two vertices for each edge in GU . So X is a vertex cover of GU . (5) Bartering. This problem is in NP. To check a feasible exchange of subset S of items of player I and subset T of items of player II, we simply check that I prefers T to S and II prefers S to T . We use a reduction from the Knapsack problem to show NP-completeness. We have n items of weights w1 , . . . , wn and values v1 , . . . , vn : Is there a set of items of weight at most W and value at least V . We set up a barter economy with just 2 people. Person I has n items that she values at w1 , . . . , wn ; Person II values these items at v1 , . . . , vn . Person II has just one item that he values at V − 1; Person I values this item at W + 1. So a trade can take place if I has a subset of item of weight at most W and that has a value of at least V . This is a polynomial reduction. (6) Galactic Shortest Paths. This problem is in NP. To check a proposed path P , we just check that it has length at most L and risk value at most R. We use a reduction from Partition to show NP-completeness. Again, we P have integers x1 , . . . , xn and we want to find a subset S ⊂ [n] with i∈S xi = P i∈S / xi . To set this up as a path problem we take a directed path (with end vertices s and t) with n arcs, one for each integer. We now make two copies of each arc i. The first copy has length xi and risk value 0; the second copy has length 0 and risk value xi . So any s − t path P in G uses exactly one the type i arcs. Let S be the set of integers where we use their first copy. Thus P the length of the path is i∈S xi ; the risk of this path is risk values on those P integers where we use the second copy of their arcs, so the risk is i∈S / xi . So P 1 set R = L = 2 i xi . Then we have a path of length at most L and risk at most R if an only if we have a valid partition. This is a polynomial reduction.