You are on page 1of 37

# NPC

## More NP-Complete Problems

Complexity 1
D.Moshkovitz
Introduction
Objectives:
To introduce more NP-Complete
problems.
Overview:
3SAT
CLIQUE & INDEPENDENT-SET
SUBSET-SUM

Complexity 2
D.Moshkovitz
Method
How to show a problem is in NPC?
First show its in NP
Then show it is NP-hard by reducing
some NP-Hard problem to it.

Complexity 3
D.Moshkovitz
New Base Problems
The only NP-Complete problem we
currently know of is SAT.
Unfortunately, its not very comfortable to
work with.
Thus well start by introducing several
useful variants of SAT.
Well use them as our base problems.

Complexity 4
D.Moshkovitz
3SAT
Instance: a 3CNF formula
Problem: To decide if the formula is satisfiable.

## An unsatifiable 3CNF formula (xxx)(xxx)

Complexity 5
D.Moshkovitz
SIP 259-260

3SAT is NP-Complete
3SAT is a special case of SAT, and is
therefore clearly in NP.
In order to show its also NP-Complete,
well alter the proof of SATs NP-
Completeness,
so it produces 3CNF formulas.

## Why would that

be enough?

Complexity 6
D.Moshkovitz
Revisiting SATs NP-
Completeness Proof
Given a TM and an input weve produced a conjunction of:

cell xi,j,s (xi,j,s xi,j,t )
1i,jnk sC s tC

start x1,1,# x1,2,q0 x1,3,w1 ... x1,n2,_ ... x1,nk 1,_ x1,nk ,#

move k x
1i,jn legal a ,...,a
1 6
i1,j,a1 ... xi1,j1,a6
accept
1i,jnk
xi,j,qaccept

Complexity 7
D.Moshkovitz
Transforming the Formula
into a CNF Formula
All the sub-formulas, but move, form a
CNF formula.
Using the distributive law we can
transform move into a conjunction of
clauses.
The formula stays succinct (check!).

Complexity 8
D.Moshkovitz
CNF 3CNF
(xy)(x1x2... xt)...
clauses with 1 or clauses with more than 3
2 literals literals

replication split

## (xyx) (x1 x2 c11)(c11 x3 c12)... (c1t-3 xt-1xt)

Complexity 9
D.Moshkovitz
3SAT is NP-Complete
Since weve shown a reduction from
any NP problem to 3SAT,
and 3SAT is in NP,
3SAT is NP-Complete.

Complexity 10
D.Moshkovitz
CLIQUE
Instance: A graph G=(V,E) and a threshold k.
Problem: To decide if there is a set of nodes
C={v1,...,vk}V, s.t for any u,vC: (u,v)E.

Complexity 11
D.Moshkovitz
CLIQUE is in NP
On input G=(V,E),k:
Guess C={v1,...,vk}V
For any u,vC: verify (u,v)E
Reject if one of the tests fail,
accept otherwise.

## The length of the certificate: O(n)

(n=|V|)
Time complexity: O(n2)
Complexity 12
D.Moshkovitz
SIP 251-253

CLIQUE is NP-Complete
Proof: Well show 3SATpCLIQUE.

## (.. .. ..) ... (.. .. ..) p

Complexity 13
D.Moshkovitz
The Reduction
for any clause ()
|V| = formulas length

K= no. of clauses
connected
iff

Complexity 14
D.Moshkovitz
Proof of Correctness
NOT
connected!

## . a clique of size k must

contain one node from
.
every layer.
.

k
Complexity 15
D.Moshkovitz
Correctness
given a k-clique, assign x TRUE or
FALSE according to whether x or x
is in the clique; this satisfies the
formula

.
.
(.. .. ..) ... (.. .. ..) .

## given a satisfying assignment, a set

comprising of one satisfied literal of
each clause forms a k-clique.

Complexity 16
D.Moshkovitz
INDEPENDENT-SET
Instance: A graph G=(V,E) and a goal k.
Problem: To decide if there is a set of nodes
I={v1,...,vk}V, s.t for any u,vI: (u,v)E.

Complexity 17
D.Moshkovitz
INDEPENDENT-SET NP
On input G=(V,E),k:
Guess I={v1,...,vk}V
For any u,vC: verify (u,v)E
Reject if one of the tests fail,
accept otherwise.

## The length of the certificate: O(n)

(n=|V|)
Time complexity: O(n2)
Complexity 18
D.Moshkovitz
INDEPENDENT-SET is NPC
Proof: By the previous claim and a
trivial reduction from CLIQUE.

## theres a clique theres an IS of

of size k in a size k in its
graph complement
Complexity 19
D.Moshkovitz
SUBSET-SUM
Instance: A multi-set of numbers denoted S
and a target number t.
Problem: To decide if there exists a subset
YS, s.t yYy=t.

Complexity 20
D.Moshkovitz
SUBSET-SUM is in NP
On input S,t:
Guess YS
Accept iff yYy=t.

## The length of the certificate: O(n) (n=|S|)

Time complexity: O(n)

Complexity 21
D.Moshkovitz
SIP 269-271
SUBSET-SUM is NP-
Complete
Proof: Well show 3SATpSUBSET-
SUM.

## (.. .. ..) ... (.. .. ..) p

Complexity 22
D.Moshkovitz
Satisfying Clauses
digit per clause

c1 c2 ck
number per variable xi
assigned true:
yi

## number per variable xi

assigned false:
zi
1 if xi is in cj
1 if xi is in cj 0 otherwise
0 otherwise
Complexity 23
D.Moshkovitz
Achieving Target
digit per clause

c1 c2 ck

0<d<4

target:

Complexity 24
D.Moshkovitz
Achieving Target
digit per clause

c1 c2 ck

1
1
target: 3

Complexity 25
D.Moshkovitz
Achieving Target
c1 c2 c k
y1
1 0 0
z1 0 0 0
...
make sure a yl 1 0 1
good subset zl 1 1 0
contains
1 0 0
exactly one
of yi and zi 1 0 0
...
0 0 1
0 0 1
3 3 3
Complexity 26
D.Moshkovitz
Imposing Consistency
c1 c2 c k
y1
1 0 0
z1 10 0 0
...
yl 1 0
0 1
zl 1 0
0 1 10
1 0 0
1 0 0
...
0 0 1
0 0 1

Complexity
1 1 1 3 3 3 27
D.Moshkovitz
Succinctness
l k

2l

2k

Complexity 28
D.Moshkovitz
Completeness
If there is a satisfying assignment,
build the subset as follows: 1 in
If the i-th variable is assigned the
TRUE, take yi, else take zi. leftmost
l digits
Add as many auxiliary numbers as
needed.
satisfiability 3
in the rightmost
k digits

Complexity 29
D.Moshkovitz
Soundness
If there is a subset which sums up to
the target, construct an assignment
as follows:
If yi is in the subset, assign TRUE to the
i-th variable.
If zi is in the subset, assign FALSE to
the i-th variable.

Complexity 30
D.Moshkovitz
Observation: No Carry
c1 c2 ck
All digits are either 1 0 0 1 0 0 y1

0 or 1. 1 0 0 0 0 0 z1

Each column
0 0 1 1 0 1 yl
contains at most
0 0 1 1 1 0 z
five 1s. l
1 0 0
Hence, a carry 1 0 0
into the next column
never occurs. 0 0 1
0 0 1

Complexity
1 1 1 3 3 3 31
D.Moshkovitz
Consistency
c1 c2 ck
0 y1
Thus, to get 1 in 1 0 0 1 0
1 0 0 0 0 0 z1
the leftmost l

digits, our subset 0 0 1 1 0 1 yl
necessarily 0 0 1 1 1 0 z
l
contains either yi 1 0 0
or zi (Not both!). 1 0 0

0 0 1
0 0 1

Complexity
1 1 1 3 3 3 32
D.Moshkovitz
Satisfiablity
c1 c2 ck
0 y1
In each column, 1 0 0 1 0
1 0 0 0 0 0 z1
at most 2 can

come from the 0 0 1 1 0 1 yl
auxiliary 0 0 1 1 1 0 z
l
numbers, so all 1 0 0
clauses are 1 0 0

satisfied.
0 0 1
0 0 1

Complexity
1 1 1 3 3 3 33
D.Moshkovitz
Summing Up
1. SUBSET-SUM is in NP
2. 3SATpSUBSET-SUM
3. Thus SUBSET-SUM is NP-Complete

Complexity 34
D.Moshkovitz
Summary
In this lecture weve added many new
problems to our NPC bank.
Interestingly, NPC contains over 1000
different problems !

Complexity 35
D.Moshkovitz
Appendix

Complexity 36
D.Moshkovitz
Dictionary
negation: not ()
conjunction: and ()
literal: (negated or not) Boolean variable disjunction: or ()
Examples: x, x
clause: several literals connected with
Example: (xyz)
CNF (Conjunctive Normal Form): several clauses
connected with
Example: (x y)(xyz)
3CNF: a CNF formula with three literals in each clause.
Example: (xyz)(xyz)

Complexity 37
D.Moshkovitz