39
The Theory of NP- Completeness 1

The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Embed Size (px)

Citation preview

Page 1: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

The Theory of NP-Completeness

1

Page 2: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

What is NP-completeness? Consider the circuit satisfiability

problem Difficult to answer the decision problem

in polynomial time with the classical deterministic algorithms

2

Page 3: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Nondeterministic algorithms

A nondeterminstic algorithm consists of

phase 1: guessing phase 2: checking If the checking stage of a nondeterministic

algorithm is of polynomial time-complexity, then this algorithm is called an NP (nondeterministic polynomial) algorithm.

3

Page 4: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

4

Nondeterministic searching algorithm

Search for x in an array A Choice(S) : arbitrarily chooses one of the elements

in set S Failure : an unsuccessful completion Success : a successful completion Nonderministic searching algorithm (which will be

performed with unbounded parallelism): j ← choice(1 : n) /* guessing */

if A(j) = x then success /* checking */ else failure

Page 5: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

5

A nondeterministic algorithm terminates unsuccessfully iff there exist not a set of choices leading to a success signal.

A deterministic interpretation of a non-deterministic algorithm can be made by allowing unbounded parallelism in computation.

The runtime required for choice(1 : n) is O(1). The runtime for nondeterministic searching

algorithm is also O(1)

Page 6: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

6

Nondeterministic sorting

B ← 0 /* guessing */for i = 1 to n do

j ← choice(1 : n) if B[j] ≠ 0 then failure B[j] = A[i]

/* checking */for i = 1 to n-1 do

if B[i] > B[i+1] then failure success

Perform the above with unbounded parallelism

Page 7: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Exercise 1

How to handle the circuit satisfiablity problem?

7

Page 8: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

NP : the class of decision problem which can be solved by a non-deterministic polynomial algorithm.

P: the class of problems which can be solved by a deterministic polynomial algorithm.

NP-hard: the class of problems to which every NP problem reduces.

NP-complete (NPC): the class of problems which are NP-hard and belong to NP.

8

Page 9: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Some concepts of NP Complete

Definition of reduction: Problem A reduces to problem B (A B) iff A can be solved by a deterministic polynomial time algorithm using a deterministic algorithm that solves B in polynomial time. B is harder.

Up to now, none of the NPC problems can be solved by a deterministic polynomial time algorithm in the worst case.

It does not seem to have any polynomial time algorithm to solve the NPC problems.

9

Page 10: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

If A, B NPC, then A B and B A Theory of NP-completeness

If any NPC problem can be solved in polynomial time, then all NP problems can be solved in polynomial time. (NP = P)

10

Page 11: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

The circuit satisfiability problem

The circuit satisfiability problem The logical formula :

x1 v x2 v x3

& - x1

& - x2 the assignment :

x1 ← F , x2 ← F , x3 ← Twill make the above formula true .

(-x1, -x2 , x3) represents x1 ← F , x2 ← F , x3 ← T

11

Page 12: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

If there is at least one assignment which satisfies a formula, then we say that this formula is satisfiable; otherwise, it is unsatisfiable.

An unsatisfiable formula : x1 v x2

& x1 v -x2

& -x1 v x2

& -x1 v -x2

12

Page 13: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Definition of the satisfiability problem: Given a Boolean formula, determine whether this formula is satisfiable or not.

  A literal : xi or -xi A clause : x1 v x2 v -x3 Ci A formula : conjunctive normal form

C1& C2 & … & Cm

13

Page 14: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Cook’s theorem

Circuit satisfiablity problem (circuit SAT) is NP-

complete. It is the first NP-complete problem. Every NP problem reduces to circuit SAT. To prove the other problems to be NP-complete,

just need to show that they are as hard as circuit SAT problem.

14

Page 15: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

All the NP problems reduce to circuit SAT

The proof is complicated Any problem in NP can be computed

with a Boolean combination circuit (i.e., a computer)

This circuit has a polynomial number of elements and can be constructed in polynomial time

The circuit runs in polynomial time so we can check the result in polynomial time

15

Page 16: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Decision problems The solution is simply “Yes” or “No”. Optimization problems are more

difficult. e.g. the traveling salesperson problem

Optimization version:Find the shortest tour

Decision version:Is there a tour whose total length is less than or equal to a constant c ?

16

Page 17: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Solving an optimization problem by a decision algorithm

Solving minimization problem by decision algorithm Give c1 and test (decision algorithm)

Give c2 and test (decision algorithm)

Give cn and test (decision algorithm)

We can find the smallest ci

17

Page 18: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Toward NP-Completeness

Once we have found an NP-complete problem, proving that other problems are also NP-complete becomes easier.

Given a new problem Y, it is sufficient to prove that Cook’s problem, or any other NP-complete problems, is polynomially reducible to Y. Known problem -> unknown problem

18

Page 19: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

NP-Completeness Proof: CLIQUE

Given that SAT problem is NP-complete, to prove that CLIQUE problem is NP-complete

Problem: Does G=(V,E) contain a clique of size k? Theorem: Clique is NP-Complete. (reduction from

SAT) Idea: Make “column” for each of k clauses.

No edge within a column. All other edges present except between x and x’

Proof: (Reduction from SAT) CLIQUE is in NP. This is trivial since we can

check it easily in polynomial time Goal: Transform arbitrary SAT instance into

CLIQUE instance such that SAT answer is “yes” iff CLIQUE answer is “yes 19

Page 20: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

NP-Completeness Proof: CLIQUE

Example:

G =

G has m-clique (m is the number of clauses in E), iff E is satisfiable.(Assign value 1 to all variables in clique)

)()()( zyzyxzyxE

x

y

z

x

y

z

y

z

20

Page 21: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Vertex Cover

Given that CLIQUE problem is NP-complete, to prove that vertex cover (VC) problem is NP-complete.

Definition: A vertex cover of G=(V, E) is V’V such that every

edge in E is incident to some vV’. Vertex Cover(VC): Given undirected G=(V, E) and

integer k, does G have a vertex cover with k vertices?

CLIQUE: Does G contain a clique of size k?

21

Page 22: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

NP-Completeness Proof: Vertex Cover(VC)

Problem: Given undirected G=(V, E) and integer k, does G have a vertex cover with k vertices?

Theorem: the VC problem is NP-complete. Proof: (Reduction from CLIQUE)

VC is in NP. This is trivial since we can check it easily in polynomial time.

Goal: Transform arbitrary CLIQUE instance into VC instance such that CLIQUE answer is “yes” iff VC answer is “yes”.

22

Page 23: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

NP-Completeness Proof: Vertex Cover(VC)

Claim: CLIQUE(G, k) has same answer as VC( , n-k), where n = |V|.

Observe: There is a clique of size k in G iff there is a VC of size n-k in .

G

G

23

Page 24: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

NP-Completeness Proof: Vertex Cover(VC)

Observe: If D is a VC in , then has no edge between vertices in V-D.So, we have k-clique in G n-k VC in

Can transform in polynomial time.

G G

G

24

Page 25: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

More convenient to use 3SAT

For a given Boolean formula in conjunctive normal form (CNF) where each clause contains three variables, find the assignment to make it true

Example: Can we find an assignment to

make E true?

25

Page 26: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

3SAT is NP Complete

Just need to rewrite SAT Given a clause with k variables in circuit SAT

When k = 1 Add two more literals to construct a

clause with 3 literals Example:

Original: ci = {x} Construction: ci_new = {(x, u1, u2)^(x,

u1’, u2’)^(x, u1, u2’)^(x, u1’, u2)}, in which ’ means negation

26

Page 27: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

3SAT is NP Complete

When k = 2 Add one literal so that the number of literals in each

clause is 3 Example:

Original: ci = {(x1, x2)} Add one literal ci_new = {(x1, x2, u)^(x1, x2, u’)}

When k > 3 Arrange these literals as a cascade of three literal clauses Example:

Original: ci = {(x1, x2, x3, … , xn)} Add one literal ci_new = {(x1, x2, u1)^(x3, u1’, u2)^ …

^(xk-2, uk-4’, uk-3)^(xk-1, xk, uk-3’)}

27

Page 28: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Subset sum problem

Def: A set of positive integers A = { a1, a2, …, an }

a constant C

Determine if A A s.t. ai = C

e.g. A = { 7, 5, 19, 1, 12, 8, 14 } C = 21, A = { 7, 14 } C = 11, no solution

a Ai

28

Page 29: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Subset sum is NP complete

Reduce from 3SAT problem E = (u1 + u3’ + u4’)(u1’ + u2 + u4’) There are 4 literals There are n = 2 clauses in the

expression above Suppose the solution is u1 = u2 = u3 =

1, u4 = 0

29

Page 30: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Table construction for subset sum

Reduce from 3SAT select row T1, T2, T3,

F4 according to solution

Select S21 and S22 to make the sum of last two columns 4

Now we have found the solution for subset sum

Table:

30

Page 31: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Basic Construction

Basic idea Create a table for the subset sum problem

The first m columns of the table stand for each one of m literals

Last n columns stand for each one of m clauses

First 2m rows stand for TRUE and FALSE of each literal

Last 2n rows stores additional number for each clause to make the sum of this column a constant

31

Page 32: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Exercise 2

To prove the following partition problem to be NP complete

Def: Given a set of positive integers A = { a1,a2,…,an },

determine if a partition P, s.t. ai = ai ip ip

32

Page 33: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Exercise 3

To prove the following bin packing problem to be NP complete

Def: n items, each of size ci , ci > 0

bin capacity : C Determine if we can assign the items

into k bins, s.t. ci C , 1jk.

ibinj

33

Page 34: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Exercise 4 To prove the following knapsack problem to be

NP complete Def: n objects, each with a weight wi > 0

a profit pi > 0 capacity of knapsack : M

Maximize pixi 1in

Subject to wixi M 1in

xi = 0 or 1, 1 i n Decision version :

Given K, pixi K ? 1in

Knapsack problem : 0 xi 1, 1 i n.

34

Page 35: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Three dimensional matching problem is NP complete

Reduce from 3SAT problem to show that three dimensional matching (3DM) problem is NP-complete.

X, Y, and Z are finite disjoint sets T = X × Y × Z Find M ⊆ T such that for any two distinct

triples (x1, y1, z1) ∈ M and (x2, y2, z2) ∈ M, we have x1 ≠x2, y1 ≠y2, and z1 ≠z2

M covers all elements in X, Y and Z

35

Page 36: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Reduce from 3SAT by example

Construct a gadget with 2k cores and 2k tips for each variable x

Example: k = 2 This gadget can work as a Boolean

variable: when x = 1, we choose cores and tips in light region; when x = 0, we choose the blue region

36

Page 37: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Build Boolean expressions

Construct a gadget for each literal in a clause

Add two cores for each clause and enclose them with tips uncovered

x1 x2 x3

C j x1 x2 x3

37

Page 38: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Proof Idea

Basic idea We choose the wings based on whether

we set a variable to true or false. We use the clean up gadgets to cover all

the rest of the tips.

38

Page 39: The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial

Summary

NP-hard and NP-complete NP-completeness proof Polynomial time reduction List of NP-complete problems Knapsack problem

39