Lecture 3 on NP-Completeness. The classical reference is Computers and Intractability A guide to the theory of NP-Completeness Michael Garey and David Johnson W H Freeman, 1979. *. Some NP-Complete Numerical Problems. 1. SUBSET SUM. Given a sequence of integers a1, ...,an, and a parameter k, decide if there is a subset of integers that sum to exactly k. It's a true decision problem, not an optimization problem forced into a decision version. Membership in NP is easy. For the completeness part, we reduce Vertex Cover to Subset Sum. Outline: o. Start with G and parameter k. o. Create a sequence of integers and parameter k' o. Prove that G has VC of size k if and only if there is subset of integers that sum to k' Reduction. For simplicity, assume the vertices of G are labeled 1, 2, ..., n. We define an integer ai for vertex i, an integer b_ij for each edge (i,j), and finally an integer k'. Our reduction will have the property that if there is a subset of ai's and b_ij's that sum to k', then: the subset of chosen ai's form a vertex cover, and the set of chosen b_ij's correspond to edges in G with exactly one endpoint in the cover. Furthermore, the size of the cover will be exactly k. Represent the integers in a matrix form. Each integer is a row, and the row shjould be seen as base-4 represention of the integer, with |E| + 1 digits. The first column of the matrix (the most significant digit) is a special one: it contains 1 for the ai's and 0 for the b_ij's. Then, there is a column (digit) for each edge. The column (i,j) has a 1 in a_i, a_j, and b_ij, and 0's everywhere else. The parameter k' is defined as k' = k(4^|E|) + \sum_{i=0}^{|E|-1} 2 (4^i) Analysis. Cover ==> Subset Sum. If there is a vertex cover of size k, then choose all integers ai for which i is in C, and all b_ij such that exactly one of i, j is in C. Then, when we sum all these integers, doing operations in base 4, we have a 2 in all digits except for the most significant one. In the MSD, we are summing one |C|=k times. Thus, the sum of integers is k'. Subset Sum ==> Cover. Suppose we find a subset C of V and E' of E such that \sum_{i \in C} ai + \sum_{(i,j) \in E'} b_ij = k' First, note that we never have a carry in the |E| less significant digits; operations are base 4, and there are at most 3 ones in each column. Since the b_ij can contribute at most 1 in every column, and k' has a 2 in all the |E| less significant digits, it means that for every edge (i,j), C must contain either i or j. So, C is a cover. Every ai is at least 4^|E|, and k' gives a quotient of k when devided by 4^|E|. So, k's cannot have more than k elements. End of proof. 2. PARTITION. Given a sequence of integers a1, ..., an, determine if there is a partition into two subsets with equal sums. Formally, is there a subset I of {1, 2, .., n} such that \sum_{i \in I} a_i = \sum_{i \not\in I} a_i. PARTITION is clearly a special case of sumset sum; the k here is just half the total sum of elements. 3. BIN PACKING. One of the most widely studied problems in CS and OR, perhaps the second most after TSP. Given items of size a1, a2, .., an, and given an unlimited supply of bins, each of size B, we want to pack items into the fewest possible bins. The decision version is to decide if the items can be packed in k or fewer binds. Clearly, an NP problems. For NP-Completeness we can reduce the PARTITION. Given an instance of PARTITION {a1, a2, ..., an}, create items of size a1, a2, ..., an. Let S = \sum a_i, be their total size. Make bin size B to be S/2, and let k = 2. The items can be packed in 2 bins if and only if the partition has a solution. 4. KNAPSACK. Subset Sum is a special case of the Knapsack problem. An instance of the Subset Sum has integers a1, ...,an, and a parameter k, and the goal is to decide if there is a subset of integers that sum to exactly k. We can frame this as a knapsack problem by introducing n items, where item i has both size and value equal to ai. The knapsack size is k. Now, the Subset Sum problem has answer YES if and only if the Knapsack problem has a solution with value k. (Because the size and value are equal, the knapsack can achieve value k only if it can be packed completely.)