1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for...

35
1.1 Chapter 3: Proving NP-completeness Chapter 3: Proving NP-completeness Results Results Six Basic NP-Complete Problems Some Techniques for Proving NP- Completeness Some Suggested Exercises

Transcript of 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for...

Page 1: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.1

Chapter 3: Proving NP-completenessChapter 3: Proving NP-completenessResultsResults

Six Basic NP-Complete Problems Some Techniques for Proving NP-

Completeness Some Suggested Exercises

Page 2: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.2

Six Basic NP-Complete ProblemsSix Basic NP-Complete Problems

3-SATISFIABILITY (3SAT) 3-DIMENSIONAL MATCHING (3DM) VERTEX COVER (VC) CLIQUE HAMILTONIAN CIRCUIT (HC) PARTITION

Page 3: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.3

3-Satisfiability3-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?

Page 4: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.4

3-Satisfiability3-Satisfiability

Theorem 3.1: 3-SAT is NP-Complete.

1) 3-SAT NP

2) SAT 3-SAT

I is satisfiable iff I’ is

AI = U,C

SAT instanceI’ = U’,C’

3-SAT instance

Page 5: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.5

3-Satisfiability3-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, yj

2}

Cj’ = { {z1, yj1, yj

2}, {z1, yj1, yj

2}, {z1, yj1, yj

2}, {z1, yj

1, yj2} }

Case 2) k=2 cj = {z1, z2}

Uj’ = {yj1}

Cj’ = { {z1, z2, yj1}, {z1, z2, yj

1} }

Page 6: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.6

3-Satisfiability3-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 {yj

i, 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} }

Page 7: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.7

3-Satisfiability3-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)

Page 8: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.8

Some More New ProblemsSome 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

Page 9: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.9

More Problems, cont.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

0

0

1

0

Page 10: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.10

H2C is NP-CompleteH2C is NP-Complete

Fact: Not All Equal 3-SAT is NP-complete

Theorem: H2C is NP-complete

1) H2C NP

2) Not All Equal 3-SAT H2C

AI = U,C

3-SAT instanceH = (V, E)H2C instance

Page 11: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.11

H2C is NP-Complete, cont.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} {vi

2 | 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, vi

2) | 0 ≤ i ≤ n-1}

Page 12: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.12

H2C is NP-Complete, cont.H2C is NP-Complete, cont.

Example:

U = {u0, u1, u2, u3}

C = { (u0, u1, u2), (u0,u2, u3), (u1, u2 u3) }

Page 13: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.13

3-Dimensional Matching3-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’.

Page 14: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.14

3-Dimensional Matching3-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.

Page 15: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.15

3-Dimensional Matching3-Dimensional Matching

Theorem: 3DM is NP-complete.

Proof:

1) 3DM NP

2) 3-SAT 3DM

AI = U,C

3-SAT instanceI’ = W,X,Y,M3DM instance

Page 16: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.16

3-Dimensional Matching3-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

Page 17: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.17

3-Dimensional Matching3-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

Page 18: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.18

Truth Setting and Fan Out ComponentsTruth 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 Ti

t or all triples from Ti

f

This corresponds to setting the variable false or true, respectively.

Page 19: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.19

Satisfaction Testing ComponentsSatisfaction 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.

Page 20: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.20

Garbage Collection ComponentsGarbage 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.

Page 21: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.21

Another Proof for Independent SetAnother 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

1) IS NP2) 3DM IS

AI = M (W,X,Y)3DM instance

G = (V, E), JIS instance

Page 22: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.22

H2C is NP-Complete, cont.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:

1) The transformation can be performed in polynomial-time

2) 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.

Page 23: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.23

Vertex Cover, Independent SetVertex Cover, Independent Setand Cliqueand 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}

Page 24: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.24

Vertex CoverVertex Cover

Theorem: VERTEX COVER is NP-complete

Proof:

1) VC NP2) 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.

Page 25: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.25

Vertex CoverVertex 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.

Page 26: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.26

Vertex CoverVertex 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…

Page 27: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.27

Hamiltonian Circuit (HS)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:

1) HC NP

2) VC HC

Page 28: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.28

PartitionPartition

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:

1) PARTITION NP

2) 3DM PARTITION

Page 29: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.29

Techniques for ProvingTechniques for ProvingNP-CompletenessNP-Completeness

There are several “general” types of transformations:

Restriction Local Replacement Component Design

Page 30: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.30

RestrictionRestriction

Proving a problem NP NP-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

Page 31: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.31

Hamiltonian Circuit (HS)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:

1) DHC NP

2) 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.

Page 32: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.32

Invalid RestrictionInvalid Restriction

Subset Sum

INSTANCE: Integers a1, a2,…,an and integer B.

QUESTION: Is there a sequence of 0’s and 1’s, x1, x2,…,xn such that:

Fact: Subset Sum is NP-complete

Real Subset Sum

INSTANCE: Integers a1, a2,…,an and integer B.

QUESTION: Is there a sequence of real numbers x1, x2,…,xn such that:

aix i B?i1

n

aix i B?i1

n

Page 33: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.33

Invalid Restriction, Cont.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.

Page 34: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.34

Local ReplacementLocal 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.

Page 35: 1.1 Chapter 3: Proving NP-completeness Results Six Basic NP-Complete Problems Some Techniques for Proving NP-Completeness Some Suggested Exercises.

1.35

PartitionPartition

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,…,Vq of 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:

1) Partition into Triangles NP

2) X3C Partition into Triangles