Homework 11 solutions
36.1-1

If longest-path-length can be solved in poly time, then to solve longest-path instance (G,u,v,k)in poly time, feed (G,u,v) to the longest-path-length solver. It will return some value, L. Say yes if L is greater than or equal to k. Otherwise say no.

For the converse, given (G,u,v) and a longest-path solver, feed (G,u,v,t) to the longest-path solver for values t=0,1,2,...n-1 where n is the number of vertices in the graph G. (n is easily determined). The largest t for which the answer is yes is the length L. This runs in poly time since it requires at most n calls to a poly time procedure.

36.1-4

I explained this in class Dec. 8. It is not poly time because W could be exponentially big in the length of the input string. If the numbers in the input string were written in unary rather than in base 2, then the algorithm would be polynomial time.

36.1-5

Let k and c be such that the algorithm, when it accepts, takes fewer than cn^k steps, where n = |x|, the length of the input string. (The constants k and c must exist by the assumption of poly time). Construct a new version of the algorithm that is identical to the original, except that it also counts how many steps it takes (not counting the steps to count the steps). If the counter reaches cn^k (technically we have to compute cn^k but this too is poly time) then we halt and reject. This algorithm is correct, for it will accept any string in L before it runs into the cn^k bound, and it rejects all other inputs. And of course the new algorithm runs in poly time.

36.2-3 This is not the most efficient, but it gets the job done. Suppose T decides HAM-CYCLE in poly time. If T says no on G, then G has no ham cycle to list. If T says yes, we have to find one such cycle. Without loss of generality, pick any vertex x in G. For every possible pair of edges incident on x, remove all edges on x except those two, and call T on the resulting graph. T must say YES on at least one of those calls. When it does, keep only those two edges on x. Pick another vertex in G and repeat the procedure, repeating until all the vertices have degree 2. Then it is easy to list a ham cycle.

36.4-6

This is even easier than 36.2-3. If B is a boolean formula in variables X1...Xn, and T determines whether an expression is satisfiable, run T on B. If T says no, there is no assignment that satisfies. If T says yes,then for i=1 to n:

(begin for) run T on (Xi AND B). If T says yes, change B to (Xi AND B). If T says no, change B to ((NOT Xi) AND B). (end for)

The satisfiying truth assignment will be the beginning of B.

36.5-1 Transform from HAM CYCLE. Given G=(V,E), create a graph C consisting of a simple cycle on |V| vertices. The pair of graphs (C,G) is in subgraph isomorphism iff G has a hamiltonian cycle. And the transformation takes poly time. Membership in NP is obvious because once you ``guess'' the mapping of vertices in G1 to vertices in G2, it only takes poly time to verify that every edge in G1 maps to one in G2.

36.5-4 Transform from subset sum. Let (S,t) be the instance of subset sum, and let T equal the sum of elements in S. Pad the instance with two new elements, with values T+t and 2T-t, respectively. The new padded instance has total sum 4T. If the new instance can be partitioned, the pad elements can't be together since each is more than ¼ of the total. (The total is 4T). So the pad elements are in separate sets. Whichever set has the 2T-t pad element must sum to 2T. So its other elements sum to t. This means that the original instance of subset sum is a YES instance. Properties 1 and 2 are very easy.