advertisement

IN210 − lecture 6 NP-completeness have no feasible solutions have feasible solutions solvable problems ; NP P NPcomplete L ∈ N Pand L ∈ N PC ⇔ L ∈ N P-hard Today: Proving N P-completeness • L ∈ N P: show that there is a “short”† certificate of membership in L (“id card”). • L ∈ N P-hard: show that there is an “efficient”† reduction from a known N P-hard problem Lnp to L. † polynomial (length, time . . . ) L1 L L np L2 L3 Autumn 1999 1 of 15 IN210 − lecture 6 Skills to learn • Transforming problems into each other. Insight to gain • Seeing unity in the midst of diversity: A variety of graph-theoretical, numerical, set & other problems are just variants of one another. But before we can use reductions we need the first N P-hard problem. L0 L1 L2 Ln NP Strategy As before: • ’Cook up’ a complete Turing machine problem • Turn it into / reduce it to a natural/known real-world problem (by using the familiar techniques). Autumn 1999 2 of 15 IN210 − lecture 6 B OUNDED H ALTING problem LBH = (M, x, 1k ) | NTM M accepts string x in k steps or less Note: 1k means k written in unary, i.e. as a sequence of k 1’s. Theorem 1 LBH is N P-complete. Proof: • LBH ∈ N P C 0 (initial config.) 1 2 3 4 1 k=4 3 2 1 1 2 accept time (steps) Certificate: (4, 2, 1, 2). The certificate, which consists of k numbers, is “short enough” (polynomial) compared to the length of the input because k is given in unary in the input! Autumn 1999 3 of 15 IN210 − lecture 6 • LBH ∈ N P-hard x MR (M,x,1PM (|x|) ) YES YES NO NO M BH ML — For every L ∈ N P there exists by definition a pair (M, PM ) such that NTM M accepts every string x that is in L (and only those strings) in PM (|x|) steps or less. — Given an instance x of L the reduction module MR computes (M, x, 1PM (|x|)) and feeds it to MBH . This can be done in time polynomial to the length of x. — If MBH says ’YES’, ML answers ’YES’. If MBH says ’NO’, ML answers ’NO’. Autumn 1999 4 of 15 IN210 − lecture 6 S ATISFIABILITY (SAT) The first real-world problem shown to be N P-complete. Instance: A set C = {C1, . . . , Cm} of clauses. A clause consists of a number of literals over a finite set U of boolean variables. (If u is a variable in U, then u and ¬u are literals over U .) Question: A clause is satisfied if at least one of its literals is TRUE. Is there a truth assignment T, T : U → {TRUE , FALSE }, which satisfies all the clauses? Example I = C ∪ U C = (x1 ∨ ¬x2), (¬x1 ∨ ¬x2), (x1 ∨ x2) U = {x1, x2} T = x1 7→ TRUE , x2 7→ FALSE is a satisfying truth assignment. Hence the given instance I is satisfiable, i.e. I ∈ SAT. ( 0 C = (x1 ∨ x2), (x1 ∨ ¬x2), (¬x1) 0 I = U 0 = {x1, x2} is not satisfiable. Autumn 1999 5 of 15 IN210 − lecture 6 Theorem 2 (Cook 1971) S ATISFIABILITY is N P-complete. Proof – main ideas: S ATISFIABILITY B OUNDED H ALTING “There is a “There is a 7−→ computation” truth assignment” computation ; (computation) matrix Example: input (M, 010, 14) b b b b b k b b b b b b b b b b b b b b b h b b Y b q3 b b b b q2 b 0 b b q1 1 0 b b s b b b b 0 1 0 b b k k Computation matrix A is polynomial-sized (in length of input) because a TM moves only one square per time step and k is given in unary. Autumn 1999 6 of 15 IN210 − lecture 6 tape squares 7−→ boolean variables Ex. Square A(2, 6) gives variables B(2, 6, 0), q B(2, 6, b), B(2, 6, 00), etc. – but only polynomially many. input symbols 7−→ single-variable clauses s s Ex. A(1, 5) = 0 gives clause B(1, 5, 0) ∈ C. Note that any satisfying truth assignment must map B(1, 5, 0s) to TRUE. rules/templates 7−→ “if-then clauses” d Ex. gives B(i − 1, j, a) ∧ B(i, j, b) a b c ∧B(i + 1, j, c) ⇒ B(i, j + 1, d) ∈ C. Note: (u ∧ v ∧ w) ⇒ z ≡ ¬u ∨ ¬v ∨ ¬w ∨ z Since the tile can be anywhere in the matrix, we must create clauses for all 2 ≤ i ≤ 2k and 1 ≤ j ≤ k, but only polynomially many. Autumn 1999 7 of 15 IN210 − lecture 6 non-determinism 7−→ “choice” variables Ex. G(1) G(2) T T F T ... k=4 F F G(t) tells us what non-deterministic choice was taken by the machine at step t. We extend the “if-then clauses” with k choice variables: G(t) ∧ “a” ∧ “b” ∧ “c” ⇒ “d” ∨ ¬G(t) ∧ · · · Note: We assume a canonical NTM which • has exactly 2 choices for each (state,scanned symbol)-pair. • halts (if it does) after exactly k steps. Autumn 1999 8 of 15 IN210 − lecture 6 Further (basic) reductions BOUNDED HALTING SATISFIABILITY (SAT) 3SAT 3-DIMENSIONAL MATCHING (3DM) VERTEX COVER (VC) HAMILTONICITY CLIQUE PARTITION Polynomial-time reductions (review) L1 ∝ L2 means that P∗ P∗ •R: → such that x ∈ L1 ⇒ fR(x) ∈ L2 and x 6∈ L1 ⇒ fR(x) 6∈ L2 L1 L2 Σ* Σ* • R ∈ Pf , i.e. R(x) is polynomial computable Autumn 1999 9 of 15 IN210 − lecture 6 S ATISFIABILITY ∝ 3- SATISFIABILITY SAT 3SAT Clauses with any 7−→ Clauses with number of literals exactly 3 literals 0 • Cj is the j’th SAT-clause, and Cj is the corresponding 3SAT-clauses. 0 • yj are new, fresh variables, only used in Cj . Cj (x1 ∨ x2 ∨ x3) 7−→ 0 Cj (x1 ∨ x2 ∨ x3) (x1 ∨ x2) 7−→ (x1 ∨ x2 ∨ yj ), (x1 ∨ x2 ∨ ¬yj ) (x1) 7−→ (x1 ∨ yj1 ∨ yj2), (x1 ∨ ¬yj1 ∨ yj2), (x1 ∨ yj1 ∨ ¬yj2), (x1 ∨ ¬yj1 ∨ ¬yj2) (x1 ∨ · · · ∨ x8) 7−→ (x1 ∨ x2 ∨ yj1), (¬yj1 ∨ x3 ∨ yj2), (¬yj2 ∨ x4 ∨ yj3), (¬yj3 ∨ x5 ∨ yj4), (¬yj4 ∨ x6 ∨ yj5), (¬yj5 ∨ x7 ∨ x8) Question: Why is this a proper reduction? Autumn 1999 10 of 15 IN210 − lecture 6 3- DIMENSIONAL MATCHING (3DM) Instance: A set M of triples (a, b, c) such that a ∈ A, b ∈ B, c ∈ C. All 3 sets have the same size q (|A| = |B| = |C| = q). Question: Is there a matching in M , i.e. a subset M 0 ⊆ M such that every element of A, B and C is part of exactly 1 triple in M 0? Example y1 x1 z1 y2 x2 z2 y3 x3 z3 M = (x1, y1, z1), (x1, y2, z2), (x2, y2, z2), (x3, y3, z3), (x3, y2, z1) We will use sets with 3 elements to visualize triples: y1 x1 Autumn 1999 z1 11 of 15 IN210 − lecture 6 Reductions are like translations from one language to another. The same properties must be expressed. 3SAT ∝ 3DM 3SAT variables x1, · · · , xn literals x1, ¬x1 clauses Cj = (x1 ∨ ¬x2 ∨ ¬x3) “There exists a sat. truth assignment” 7−→ 7−→ 7−→ 7−→ 3DM variables xj3, aj3, b2j , c1k variables xj1, ¬xj1 triples (xj1, b1j , b2j ) (¬xj3, b1j , b2j ) ”There is a matching” “There is a truth assignment T ” • ∃T : {x1, · · · , xn} → {TRUE, FALSE } • T (xi) = TRUE ⇔ T (¬xi) = FALSE The second property is easily translated to the 3DM-world: xi ¬xi ai T (Xi) = Autumn 1999 TRUE 7−→ x1is not “married” 12 of 15 IN210 − lecture 6 A literal xi can be used in many clauses. In 3DM we must have as many copies of xi as there are clauses: x1i ¬x4i ¬x1i x4i x2i ¬x3i ¬x2i x3i • Either all the black triples must be chosen (“married”) or all the red ones! • If T (xi) = TRUE then we choose all the red triples, and the black copies of xi are free to be used later in the reduction. And vice versa. • We make one such truth setting component for each variable xi in 3SAT. Autumn 1999 13 of 15 IN210 − lecture 6 “T is satisfying” We translate each clause (example: Cj = (x1 ∨ ¬x2 ∨ ¬x3)) into 3 triples: xj1 ¬xj2 b1j ¬xj3 b2j • b1j and b2j can be married if and only if at least one of the literals in Cj is not married in the truth setting component. • If we have a satisifiable 3SAT-instance , then all b1j and b2j -variables (1 ≤ j ≤ m) can be married. • If we have a negative 3SAT-instance , then some b1j and b2j -variables will not be married. Autumn 1999 14 of 15 IN210 − lecture 6 Cleaning up (“Garbage collection”) There are many xji who are neither married in the truth settting components nor in the “clause-satisfying” part. We introduce a number of fresh c-variables who can marry “everybody”: x11 ¬x11 xm n ··· c1k ¬xm n c2k • There are m × n unmarried x-variables after the truth setting part. • If all m clauses are satisfiable then there will remain (m × n) − m = m(n − 1) unmarried x-variables. • So we let 1 ≤ k ≤ m(n − 1). Autumn 1999 15 of 15