=========================================================================== CSC 363H Lecture Summary for Week 10 Fall 2005 =========================================================================== --------------- NP-completeness --------------- - Cook-Levin Theorem: SAT is NPc SAT in NP: Given , check that c encodes an assignment of truth values to the variables of F that makes F evaluate to TRUE. This can be done in polytime, and F is satisfiable iff there is some value of c that makes the verifier accept. SAT is NP-hard: (high-level idea only) For an arbitrary language A in NP, by definition, there is some NTM M_A that decides A in time <= C n^k for some constants C, k. Given an input x, we can construct a formula F_x that describes possible computation paths (of length at most C |x|^k) of M_A on x, such that F_x is satisfiable iff there is some computation path of M_A that accepts x. Intuitively, we are simulating the TM model of computation using propositional formulas, which are similar to digital circuits. Details are in the textbook and are needed to ensure that this can be done in polytime. In general, to prove A is NP-hard, it's sufficient to show B <=p A for some B known to be NP-hard: if B <=p A then for all L in NP, L <=p B (by definition of NP-hardness for B) so L <=p A (since <=p is transitive). 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: - 3SAT is NPc: 3SAT in NP because it's a special case of SAT. In proof of Cook-Levin, possible to construct formula F_x in CNF, so CNF-SAT is NP-complete; CNF-SAT <=p 3SAT already proven (see additional lecture notes for week 9 -- you are responsible for reading them, understanding them, and asking questions if you don't understand). Note: Careful with directions! Trivially, 3SAT <=p CNF-SAT (3SAT is special case of CNF-SAT). But we need other direction, transforming instances of general problem into instances of restricted problem. - VERTEX-COVER is NPc: (see textbook) VERTEX-COVER (VC for short) = { : G is a graph that contains a vertex cover of size k, i.e., a set of k vertices C such that each edge of G has at least one endpoint in C } . VC in NP: certificate = vertex cover of size k. . VC is NP-hard: 3SAT <=p VC. Given F = (a1 \/ b1 \/ c1) /\ ... /\ (ar \/ br \/ cr), where ai,bi,ci in {x1,~x1,x2,~x2,...,xs,~xs}, construct G=(V,E) and k such that F satisfiable iff G contains vertex cover of size k, as follows: k = s + 2r V = { a1,b1,c1, ..., ar,br,cr, x1,~x1, ..., xs,~xs } E = { (xi,~xi) : 1 <= i <= s } U { (ai,bi),(bi,ci),(ci,ai) : 1 <= i <= r } U { (l,x) : l = ai or bi or ci, and x = xj or ~xj corresponding to l } For example, if F = (x1 \/ ~x2 \/ ~x4) /\ (x2 \/ ~x3 \/ x1) /\ (~x3 \/ x4 \/ ~x2), then a1=x1, b1=~x2, c1=~x4, a2=x2, b2=~x3, c2=x1, a3=~x3, b3=x4, c3=~x2 so k = 4 + 2*3 = 10 V = { a1,b1,c1, a2,b2,c2, a3,b3,c3, x1,~x1, x2,~x2, x3,~x3, x4,~x4 } E = { (x1,~x1), (x2,~x2), (x3,~x3), (x4,~x4), (a1,b1), (b1,c1), (c1,a1), (a1,x1), (b1,~x2), (c1,~x4), (a2,b2), (b2,c2), (c2,a2), (a2,x2), (b2,~x3), (c2,x1), (a3,b3), (b3,c3), (c3,a3), (a3,~x3), (b3,x4), (c3,~x2) } Clearly, construction can be done in polytime (with one scan of F). Also, if F is satisfiable, then there is an assignment of truth values that make at least one literal in each clause true. Pick a cover C as follows: for each variable, C contains xi or ~xi, whichever is true under the truth assignment; for each clause, C contains every literal except one that's true (pick arbitrarily if more than one true literal). C contains exactly s+2r vertices and is a cover: all edges (xi,~xi) are covered; all edges in clause triangles are covered (because we picked two vertices from each triangle); all edges between "clauses" and "variables" are covered (two from inside triangle, one from true literal for that clause). Finally if G contains a cover C of size k=s+2r, C must contain at least one of xi or ~xi for each i (because of edges (xi,~xi)) and at least two of ai,bi,ci for each i (because of triangle), so only way for C to have size s+2r is to contain exactly one of xi or ~xi and exactly two of ai,bi,ci, for each i. Since C covers all edges with only two vertices per triangle, the third vertex in each triangle must have its "outside" edge covered because of xi or ~xi. If we set literals according to choices of xi or ~xi in C, this will make formula F true: at least one literal will be true in each clause (because at least one edge from "variables" to "clauses" is covered by the variable in C).