=========================================================================== CSC 363H Lecture Summary for Week 10 Summer 2006 =========================================================================== Template for proofs of NP-completeness: To show A is NPc, prove that A in NP: Describe a polytime verifier for A. "Given , check c has right format and properties..." Argue that verifier runs in polytime and that x in A iff verifier accepts for some c. A is NP-hard: Show B <=p A for some NP-hard B. "Given y, construct x as follows: ..." Argue that construction can be carried out in polytime and that y in B iff x in A (often by showing y in B -> x in A and x in A -> y in B). Examples: INDEPENDENT-SET = { | G is an undirected graph that contains an independent set of size k -- a subset of vertices with NO edge between any two of them } - INDEPENDENT-SET (IS) is NPc: . in NP: certificate = independent set . NP-hard: VC <=p IS: Given , construct as follows: G' = G, k' = n-k. Clearly this can be done in polytime. Also, if G contains a vertex cover of size k, the vertices outside the cover form an independent set of size n-k. Finally, if G' contains an independent set of size n-k, the vertices outside the independent set form a vertex cover of size k. - CLIQUE is NPc: Already known in NP. For NP-hardness, use reduction from INDEPENDENT-SET: On input , construct as follows: G' = complement of G (same vertices, edge in G' iff edge not in G) k' = k This construction can obviously be carried out in polytime. Moreover, if G contains an I.S. of size k, then the same set in G' will be a clique of size k; conversely, if G' contains a clique of size k, the same set in G will be an I.S. of size k. Note: textbook uses different reduction from 3SAT. - SUBSET-SUM = { | S = {x_1,x_2,...,x_k} and there is a set {y_1,y_2,...,y_j} such that SUM y_i = t } SUBSET-SUM is NPc: . in NP: verifier = "On input : 1. check that c encodes a set of numbers; 2. check that c subset of S; 3. check that SUM_{y in c} y = t; 4. accept if all checks pass, reject otherwise." Clearly runs in polytime, and accepts for some c iff in SUBSET-SUM. . NP-hardness: 3SAT <=p SS: Given formula F = (a1 \/ b1 \/ c1) /\ ... /\ (ar \/ br \/ cr) where ai,bi,ci in {x1,~x1,...,xs,~xs}, construct numbers as follows: . For j = 1,...,s, number xj = 1 followed by s-j 0s followed by r digits where k-th next digit equals 1 if xj appears in clause C_k, 0 otherwise; number ~xj = 1 followed by s-j 0s followed by r digits where k-th next digit equals 1 if ~xj appears in clause C_k, 0 otherwise. . For j = 1,...,r, number Cj = 1 followed by r-j 0s and number C'j = 2 followed by r-j 0s. . Target t = s 1s followed by r 4s. Clearly, this can be constructed in polytime. Example of reduction for F = (x1 \/ ~x2 \/ ~x4) /\ (x2 \/ ~x3 \/ x1) /\ (~x3 \/ x4 \/ ~x2): S = { x1 = 1000110, ~x1 = 1000000, x2 = 0100010, ~x2 = 0100101, x3 = 0010000, ~x3 = 0010011, x4 = 0001001, ~x4 = 0001100, C1 = 0000100, C'1 = 0000200, C2 = 0000010, C'2 = 0000020, C3 = 0000001, C'3 = 0000002 } t = 1111444 Note: slightly different from book to ensure S contains all distinct numbers (book's reduction constructs S with repeated numbers). If F is satisfiable, then there is a setting of variables such that each clause of F contains at least one true literal. Consider the subset S' = {numbers that correspond to true literals}. By construction, SUM_{x in S'} x = s 1s followed by r digits, each one of which is either 1, 2, or 3 (because each clause contains at least one true literal). This means it is possible to add suitable numbers from {C1,C'1,...,Cr,C'r} so that the last r digits of the sum are equal to 4, i.e., there is a subset S' such that SUM_{x in S'} x = t. If there is a subset S' of S such that SUM_{x in S'} x = t, then S' must contain exactly one of {xj,~xj} for j = 1,...,n, because that is the only way for the numbers in S' to add to the target (with a 1 in the first s digits). Then, F is satisfied by setting each variable according to the numbers in S': for each clause j, the corresponding digit in the target is equal to 4 but the numbers Cj and C'j together only add up to 3 in that digit; this means that the selection of numbers in S' must include some literal with a 1 in that digit, i.e., clause j contains at least one true literal.