360 likes | 992 Views
Chapter 3: Proving NP-completeness Results. Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises. Six Basic NP-Complete Problems. 3-SATISFIABILITY (3SAT) 3-DIMENSIONAL MATCHING (3DM) VERTEX COVER (VC) CLIQUE HAMILTONIAN CIRCUIT (HC)
E N D
Chapter 3: Proving NP-completenessResults • Six Basic NP-Complete Problems • Some Techniques for Proving NP-Completeness • Some Suggested Exercises
Six Basic NP-Complete Problems • 3-SATISFIABILITY (3SAT) • 3-DIMENSIONAL MATCHING (3DM) • VERTEX COVER (VC) • CLIQUE • HAMILTONIAN CIRCUIT (HC) • PARTITION
3-Satisfiability • A restricted version of satisfiability in which all instances have exactly 3 literals per clause. 3-SATISFIABILITY (3-SAT) INSTANCE: Collection C = {c1, c2,…,cm} of clauses on a finite set U of variables such that {cj} = 3, for 1 ≤ j ≤ m. QUESTION: Is there a truth assignment for U that satisfies all the clauses in C?
A I’ = U’,C’ 3-SAT instance I = U,C SAT instance 3-Satisfiability Theorem 3.1: 3-SAT is NP-Complete. • 3-SAT NP • SAT 3-SAT I is satisfiable iff I’ is
3-Satisfiability • Each clause cj in I => a set Cj’ of clauses with new variables Uj’ • Let cj = {z1, z2,…,zk} where zi’s are literals derived from variables in U • Case 1) k=1 cj = {z1} Uj’ = {yj1, yj2} Cj’ = { {z1, yj1, yj2}, {z1, yj1, yj2}, {z1, yj1, yj2}, {z1, yj1, yj2} } • Case 2) k=2 cj = {z1, z2} Uj’ = {yj1} Cj’ = { {z1, z2, yj1}, {z1, z2, yj1} }
3-Satisfiability • Case 3) k=3 cj = {z1, z2, z3} Uj’ = {} Cj’ = { {z1, z2, z3} } • Case 4) k>=4 cj = {z1, z2,…,zk} Uj’ = {yji | 1 ≤ i ≤ k-3} Cj’ = { {z1, z2, yj1} } U {yji, zi+2, yji+1 } | 1 ≤ i ≤ k-4} U {yjk-3, zk-1, zk } } Example: cj = {z1, z2, z3, z4, z5, z6} Uj’ = { {z1, z2, a}, {a, z3, b}, {b, z4, c}, {c, z5, z6} }
3-Satisfiability • Finally, let: U’ = U { Uj’ | 1 ≤ j ≤ m } C’ = { Cj’ | 1 ≤ j ≤ m } • Claim: 1) I = U,C is satisfiable iff I’ = U’,C’ is satisfiable. 2) I’ can be computed in polynomial time. Let m = |C|, n = |U| case 1) creates 4 clauses case 2) creates 2 clauses case 3) creates 1 clause case 4) creates k-1 clauses, where k is the number of literals in the clause This gives a total of at most k-1 new clauses in I’ for each clause in I Therefore, there is a total of m*(k-1) clauses in I’ Since k<=2n, it follows that there are at most 2nm clauses in I’, which is O(mn)
Some More New Problems Not All Equal 3-SAT INSTANCE: Collection C = {c1, c2,…,cm} of clauses on a finite set U of variables such that {cj} = 3, for 1 ≤ j ≤ m. QUESTION: Is there a truth assignment for U such that each clause in C has at least one true literal and at least one false literal? • Examples: { (a, b, c), (a, b, c), (a, b, c) } a = T, b = T, c = F { (a, b, c), (a, b, c), (a, b, c), Not even satistfiable (a, b, c), (a, b, c), (a, b, c) (a, b, c), (a, b, c) } { (a, b, c), (a, b, c), (a, b, c), Satistfiable, but not with (a, b, c), (a, b, c), (a, b, c) at least one literal true and false (a, b, c) } per clause
More Problems, cont. Hypergraph 2-Colorability (H2C) INSTANCE: Hypergraph H = (V, E), where 2 ≤ |ei| ≤ 3, for all ei E. QUESTION: Is H 2-colorable? In other words, is there a function f : V {0, 1} such that for all ei E there exist vertices u,v ei such that f(u) f(v)? Examples: No Yes No 0 1 1 0 0 0
A H = (V, E) H2C instance I = U,C 3-SAT instance H2C is NP-Complete Fact: Not All Equal 3-SAT is NP-complete Theorem: H2C is NP-complete • H2C NP • Not All Equal 3-SAT H2C
H2C is NP-Complete, cont. • Suppose I = U,C where: U = {u0, u1,…,un-1} C = {c0, c1,…,cm-1} • Construct H = (V, E) where: V = { vi1 | ui U} {vi2 | ui U} vi1 corresponds to ui vi2 corresponds to the complement of ui E = E1 E2 where E1 = { (v1, v2, v3) | ci C, ci = (z1, z2, z3) and v1, v2, v3 are the vertices corresponding to the literals z1, z2 and z3, respectively} E2 = { (vi1, vi2) | 0 ≤ i ≤ n-1}
H2C is NP-Complete, cont. • Example: U = {u0, u1, u2, u3} C = { (u0, u1, u2), (u0,u2, u3), (u1, u2 u3) }
3-Dimensional Matching 3-DIMENSIONAL MATCHING (3-DM) INSTANCE: A set M W X Y, where W, X and Y are disjoint sets having the same number q of elements. QUESTION: Does M contain a matching, that is, a subset M’ M sucht at |M| = q and no two elements of M’ agree in any coordinate? Example #1: q = 3 (not part of input technically) W = {a1, a2, a3} X = {b1, b2, b3} Y = {c1, c2, c3} M = { (a1, b2, c1), (a2, b1, c3), (a3, b3, c2), (a1, b1, c3), (a2, b2, c1) } Yes! The first 3 form a matching. Note that every element in each set will appear in exactly one triple in M’.
3-Dimensional Matching Example #2: q = 3 (not part of input technically) W = {a1, a2, a3} X = {b1, b2, b3} Y = {c1, c2, c3} M = { (a1, b1, c1), (a1, b1, c2), (a2, b1, c3), (a3, b1, c1) } No! In fact b1 and b3 do not appear in any triple.
A I’ = W,X,Y,M 3DM instance I = U,C 3-SAT instance 3-Dimensional Matching Theorem: 3DM is NP-complete. Proof: • 3DM NP • 3-SAT 3DM
3-Dimensional Matching • Suppose I = U,C where: U = {u1, u2,…,un} C = {c1, c2,…,cm} • Construct M as follows. • M will consists of three types of “components:” • Truth Setting and fan-out • Satisfaction testing • Garbage collection
3-Dimensional Matching • Suppose I = U,C where: U = {u1, u2,…,un} C = {c1, c2,…,cm} • Construct M as follows. • M will consists of three types of “components:” • Truth Setting and fan-out • Satisfaction testing • Garbage collection
Truth Setting and Fan Out Components • For each variable ui U, create the following elements: Tit = { (ui[j], ai[j], bi[j]) | 1 ≤ j ≤ m } U Tif = { (ui[j], ai[j+1], bi[j]) | 1 ≤ j ≤ m-1 } U { (ui[m], ai[1], bi[m]) } a big “blob” for each Boolean variable (see page 51) • Observation #1: Creates 2mn elements in W, mn in X and mn in Y. • ui[j] represents the fact that variable ui could occur in clause cj. • Similarly for ui[j] • Observation #2: ai[j] and bi[j] both occur in exactly two triples and nowhere else. • Observation #3: This tells us that in any matching M’ M we must have all white or all shaded triples, in other words, all triples from Tit or all triples from Tif • This corresponds to setting the variable false or true, respectively.
Satisfaction Testing Components • For each clause cj C, create three triples: Cj = { (ui[j], s1[j], s2[j]) | ui cj} U { (ui[j], s1[j], s2[j]) | ui cj } • Observation #4: This adds m elements to X, and m elements to Y. • Observation #5: For each j, 1 ≤ j ≤ m, s1[j] and s2[j] both appear in exactly three triples and nowhere else. • Observation #6: Any matching must choose exactly one triple from Cj • This corresponds to making that literal true.
Garbage Collection Components • For each clause cj C, create three triples: G = { (ui[j], g1[k], g2[k]), (ui[j], g1[k], g2[k]) | 1 ≤ k ≤ m(n-1), 1 ≤ i ≤ n, 1 ≤ j ≤ m} • Observation #7: This adds m(n-1) elements to X, and to Y. • Observation #8: For each k, 1 ≤ k ≤ m(n-1), g1[k] and g2[k] both appear in exactly 2mn triples and nowhere else. • Observation #9: Exactly m(n-1) triples from G must occur in any matching for M (why?). • Observation #10: |W| = |X| = |Y| = 2mn = q.
A G = (V, E), J IS instance I = M (W,X,Y) 3DM instance Another Proof for Independent Set INDEPENDENT SET (IS) INSTANCE: Graph G = (V, E) and positive integer J <= |V|. QUESTION: Does G contain an independent set of size J or more? Theorem: IS is NP-complete • IS NP • 3DM IS
H2C is NP-Complete, cont. Proof: Let M be an instance of 3DM, and construct an instance of IS as follows. V = {vi | ti M} E = {vi, vj | i j and ti and tj agree on some coordinate} j = q Claims: • The transformation can be performed in polynomial-time • M contains a matching if and only if G=(V,E) contains a vertex cover of size j. (only if) Let M’ = {t0, t1,…,tq-1} be a matching, where M’ M. It can be easily verified that V’ = {v0, v1,…,vq-1} is an independent set of size j. (if) Let V’ = {v0, v1,…,vq-1} is an independent set of size j for G. Then it can be easily verified that M’ = {t0, t1,…,tq-1} is a matching.
Vertex Cover, Independent Setand Clique VERTEX COVER (VC) INSTANCE: A Graph G = (V, E) and a positive integer K <= |V|. QUESTION: Is there a vertex cover of size K or less for G, that is, a subset V’ V such that |V’| <= K and, for each edge {u,v} E, at least one of u and v belongs to V’? INDEPENDENT SET (IS) INSTANCE: Graph G = (V, E) and positive integer J <= |V|. QUESTION: Does G contain an independent set of size J or more? CLIQUE INSTANCE: A Graph G = (V, E) and a positive integer J <= |V|. QUESTION: Does G contain a clique of size J or more? Lemma 3.1: For any graph G=(V,E) and subset V’ V, the following statements are equivalent: (a) V’ is a vertex cover for G (b) V-V’ is an independent set for G (c) V-V’ is a clique in the complement Gc of G, where Gc=(V,Ec) with Ec={{u,v} | u,v V and {u,v} E}
Vertex Cover Theorem: VERTEX COVER is NP-complete Proof: • VC NP • 3SAT VC Suppose I = U,C is an instance of 3SAT where: U = {u1, u2,…,un} C = {c1, c2,…,cm} We will construct a graph G=(V,E) and a positive integer K<=|V| such that G has a vertex cover of size K or less if and only if C is satistfiable. For each variable ui U, there is a truth-setting component Ti=(Vi,Ei) where: Vi = {ui, ui} and Ei = {{ui,ui}} *Note that any vertex cover will have to contain at least on of ui and its complement.
Vertex Cover For each clause cj C, create a satisfaction testing component Sj = (Vj’, Ej’): Vj’= { a1[j], a2[j], a3[j] } Ej’ = { {a1[j], a2[j]}, {a1[j], a3[j]}, {a2[j], a3[j]} } *Note that any vertex cover will have to contain at least two vertices from Vj’ in order to cover the edges in Ej’. For each clause cj C, let the three literals in cj be xj, yj, zj. Then add communication edges: Ej’’ = { {a1[j], xj}, {a2[j], yj}, {a3[j], zj} } Finally, let K = n + 2m. See page 55 for an example.
Vertex Cover Observations: • The transformation can be performed in polynomial-time. • G = (V, E) will have a vertex cover of size K or less IFF I = U,C is satisfiable. (if) Suppose I = U,C is satisfiable… (only if) Suppose G = (V, E) has a vertex cover of size K or less…
Hamiltonian Circuit (HS) HAMILTONIAN CIRCUIT (HC) INSTANCE: A Graph G = (V, E). QUESTION: Does G have a Hamiltonian circuit, that is an ordering < v1, v2,…,vn > of the vertices of G, where n = |V|, such that {vn, v1} E and {vi, vi+1} E for all i, 1 ≤ i n. VERTEX COVER (VC) INSTANCE: A Graph G = (V, E) and a positive integer K <= |V|. QUESTION: Is there a vertex cover of size K or less for G, that is, a subset V’ V such that |V’| <= K and, for each edge {u,v} E, at least one of u and v belongs to V’? Theorem: HC is NP-complete Proof: • HC NP • VC HC
Partition PARTITION INSTANCE: A finite set A and a “size” s(a) Z+for each a A. QUESTION: Is there a subset A’ A such that 3-DIMENSIONAL MATCHING (3-DM) INSTANCE: A set M W X Y, where W, X and Y are disjoint sets having the same number q of elements. QUESTION: Does M contain a matching, that is, a subset M’ M such at |M| = q and no two elements of M’ agree in any coordinate? Theorem: Partition is NP-complete Proof: • PARTITION NP • 3DM PARTITION
Techniques for ProvingNP-Completeness There are several “general” types of transformations: • Restriction • Local Replacement • Component Design
Restriction • Proving a problem NPNP-complete by restriction consists of showing that contains another known NP-complete problem ’ as a special case. • What is a “special case” of a problem? • Let I be all instances of a problem , and let I’ be all instances of a problem ’ • If I’ I then ’ is a special case of ’ • Furthermore, if and ’ are both in NP, and if is NP-complete, then so is ’ • The heart of a proof by restriction is the specification of additional restrictions to be placed on the instances of so that the resulting problem will be identical to ’ • Note that a proof by restriction is still a transformation, i.e., it is not a different kind of NP-completeness proof
Hamiltonian Circuit (HS) DIRECTED HAMILTONIAN CIRCUIT (DHC) INSTANCE: A directed graph G = (V, E). QUESTION: Does G have a Hamiltonian circuit, that is an ordering < v1, v2,…,vn > of the vertices of G, where n = |V|, such that {vn, v1} E and {vi, vi+1} E for all i, 1 ≤ i n. HAMILTONIAN CIRCUIT (HC) INSTANCE: A Graph G = (V, E). QUESTION: Does G have a Hamiltonian circuit, that is an ordering < v1, v2,…,vn > of the vertices of G, where n = |V|, such that {vn, v1} E and {vi, vi+1} E for all i, 1 ≤ i n. Theorem: DHC is NP-complete Proof: • DHC NP • HC DHC, by restriction. Consider those instances of DHC where there is an edge from u to v if and only if there is an edge from v to u.
Invalid Restriction Subset Sum INSTANCE: Integers a1, a2,…,anand integer B. QUESTION: Is there a sequence of 0’s and 1’s, x1, x2,…,xnsuch that: Fact: Subset Sum is NP-complete Real Subset Sum INSTANCE: Integers a1, a2,…,anand integer B. QUESTION: Is there a sequence of real numbers x1, x2,…,xnsuch that:
Invalid Restriction, Cont. • Claim (from a Ph.D disseration): • Subset Sum is just a special case of Real Subset Sum • Therefore, Real Subset Sum is NP-complete • The proof is in error since it restricts the question, and not the instances. • The problem is actually trivially solvable in polynomial time simply taking x1 = B/a1 and xi = 0, for all i, where 2 ≤ i ≤ n.
Local Replacement • Transformations are sufficiently non-trivial to warrant spelling out details, in contrast to restriction. • An instance of a known NP-complete problem is broken up into some number of structurally similar “basic units” • During the transformation, each “basic unit” is replaced by a different structure, which is part of the target problems instance. • Each replacement constitutes only local modification.
Partition Exact Cover by 3-Sets (X3C) INSTANCE: Set X with |X| = 3q and a collection C of 3-element subsets of X. QUESTION: Does C contain a an exact cover for X, i.e., a subcollection C’ C such that every element of X occurs in exactly one member of C’? Fact: X3C is NP-complete (by restriction from 3DM) Partition into Triangles INSTANCE: A Graph G = (V, E), with |X| = 3q. QUESTION: Is there a partition of V into q disjoint sets V1, V2,…,Vqof three vertices each such that, for each Vi = {vi[1], vi[2], vi[3]} the three edges {vi[1], vi[2]} , {vi[1], vi[3]} and {vi[2], vi[3]} all belong to E’? Theorem: Partition into Triangles is NP-complete Proof: • Partition into Triangles NP • X3C Partition into Triangles