16
NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV) Dasgupta, Papadimitriou, and Vazirani. Algorithms

NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

Embed Size (px)

DESCRIPTION

NP Def. Algorithm C(s, t) is a certifier for problem X if for every string s, s  X iff there exists a string t such that C(s, t) = yes. NP. Decision problems for which there exists a poly-time certifier. Remark. NP stands for nondeterministic polynomial-time.

Citation preview

Page 1: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

NP-Completeness

Note. Some illustrations are taken from(KT) Kleinberg and Tardos. Algorithm Design(DPV) Dasgupta, Papadimitriou, and Vazirani. Algorithms

Page 2: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

Decision problemsDecision problem.• X is a set of strings.• Instance: string s.• Algorithm A solves problem X: A(s) = yes iff s X.

Polynomial time. Algorithm A runs in poly-time if for every string s, A(s) terminates in at most p(|s|) "steps", where p() is some polynomial.

Page 3: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

NPDef. Algorithm C(s, t) is a certifier for problem X if for every string s, s X iff there exists a string t such that C(s, t) = yes.

NP. Decision problems for which there exists a poly-time certifier.

Remark. NP stands for nondeterministic polynomial-time.

Page 4: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

Polynomial transformations

Def. Problem X polynomial transforms to problem Y if given any input x to X, we can construct in polynomial time an input y to Y such that x is a yes instance of X iff y is a yes instance of Y.

Notation. X ≤P Y

Algorithm for X

Algorithm for Yx y

Transf.yes

no

Page 5: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

NP-completenessDef. Problem Y is NP-complete if• Y is in NP and • for every problem X in NP, X P Y.

Theorem. Suppose Y is an NP-complete problem. Then Y is solvable in polynomial time iff P = NP.

Page 6: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

Circuit satisfiability

1 0 ? ? ?

output

inputshard-coded inputs

yes: 1 0 1

KT

Page 7: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

Proving NP-completeness

Fact (Transitivity of p). If X P Y and Y P Z, then X P Z.

Theorem. Problem Y is NP-complete if• Y is in NP and • There exists some NP-complete problem X such that X P Y.

Proof. By def. of NP and transitivity of P.

Page 8: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

Map of reductionsCIRCUIT-SAT

3-SAT

DIR-HAM-CYCLEINDEPENDENT SET

VERTEX COVER

3-SAT r

educes t

o

INDEPE

NDENT

SET

GRAPH 3-COLOR

HAM-CYCLE

TSP

SUBSET-SUM

SCHEDULINGPLANAR 3-COLOR

SET COVER

KT

Page 9: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

3-SAT P INDEPENDENT SET

DPV

Page 10: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

3-SAT P DIR-HAM-CYCLE

s

t

clause nodeclause node

x1

x2

x3

3k + 3 KT

Page 11: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

3-SAT P 3-COLOR

T

B

F

x1

x1

x2

x2

xn

xn

x3

x3

true false

base

Variable gadgets. Ensure thati. each literal is T or F andii.a literal and its negation are opposites.

KT

Page 12: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

3-SAT P 3-COLORClause gadgets. Ensure that at least one literal in each clause is T.

T F

B

x1

x2

x3

6-node gadget

true false

KT

Page 13: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

3-SAT P SUBSET SUM

dummies to getclause columnsto sum to 4

y

x

z

0 0 0 0 1 00 0 0 2 0 00 0 0 1 0 00 0 1 0 0 1

0 1 0 0 1 10 1 0 1 0 01 0 0 1 0 11 0 0 0 1 0

0 0 1 1 1 0

x y z C1 C2 C3

0 0 0 0 0 20 0 0 0 0 10 0 0 0 2 0

1 1 1 4 4 4

x

y

z

W

KT

Page 14: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

CIRCUIT SAT P SAT• For each gate g in the circuit, create a variable g.

• Model g using a few clauses:

• If g is the output gate, we force it to be true by adding the clause (g).

DPV

Page 15: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

A NP, A P CIRCUIT SAT

Since A NP, there is an algorithm C(s,t) such that:

• C checks, given an instance s and a proposed solution t, whether or not t is a solution of s.

• C runs in polynomial time.

In polynomial time, build a circuit D such that:• Known inputs of D are the bits of s. • Unknown inputs of D are the bits of t.• C’s answer is given at the output gate of D.• Size of D is polynomial in the number of inputs. • D‘s output is true if and only if t is a solution of s.

Page 16: NP-Completeness Note. Some illustrations are taken from (KT) Kleinberg and Tardos. Algorithm Design (DPV)Dasgupta, Papadimitriou, and Vazirani. Algorithms

Example: Does G have an independent set of

size 2?

u-v

1

independent set of size 2?

hard-coded inputs (graph description)

u-w

0

v-w

1

u?

v?

w?

set of size 2?

both endpoints of some edge have been chosen?

independent set?

u

v w

G = (V, E), n = 3

KT