NP-complete Languages
Fall 2005 Costas Busch - RPI 1
Polynomial Time Reductions
Polynomial Computable function f :
There is a deterministic Turing machine M
such that for any string w computes f (w)
in polynomial time: O (| w |k
)
Fall 2005 Costas Busch - RPI 2
Observation:
| f (w ) | O (| w | ) k
since, M cannot use
more than O (| w |k ) tape space
in time O (| w |k )
Fall 2005 Costas Busch - RPI 3
Definition:
Language A
is polynomial time reducible to
language B
if there is a polynomial computable
function f such that:
w A f ( w) B
Fall 2005 Costas Busch - RPI 4
Theorem:
Suppose that A is polynomial reducible to B.
If B P then A P .
Proof:
Let M be the machine that decides B
in polynomial time
Machine M to decide A in polynomial time:
On input string w : 1. Compute f (w)
2. Run M on input f (w)
3. If f (w ) B acccept w
Fall 2005 Costas Busch - RPI 5
Example of a polynomial-time reduction:
We will reduce the
The 3CNF-satisfiability problem
to
The clique problem
Fall 2005 Costas Busch - RPI 6
3CNF formula: literal
( x1 x2 x3 ) ( x3 x5 x6 ) ( x3 x6 x4 ) ( x4 x5 x6 )
clause
Each clause has three literals
Language:
3CNF-SAT ={ w : w is a satisfiable
3CNF formula}
Fall 2005 Costas Busch - RPI 7
A 5-clique in graph G
Language:
CLIQUE = { G, k : graph G
contains a k-clique}
Fall 2005 Costas Busch - RPI 8
Theorem: 3CNF-SAT is polynomial time
reducible to CLIQUE
Proof: give a polynomial time reduction
of one problem to the other
Fall 2005 Costas Busch - RPI 9
Transform formula to graph.
Example:
( x 1 x 2 x 4 ) (x 1 x 2 x 4 ) ( x 1 x 2 x 3 ) ( x 2 x 3 x 4 )
Clause 2
Create Nodes: x1 x2 x4 Clause 3
x1 x1
Clause 1 x2 x2
x4 Clause 4 x3
x2 x3 x4
Fall 2005 Costas Busch - RPI 10
( x 1 x 2 x 4 ) (x 1 x 2 x 4 ) ( x 1 x 2 x 3 ) ( x 2 x 3 x 4 )
x1 x2 x4
x1 x1
x2 x2
x4 x3
x2 x3 x4
Add link from a literal to a literal in every
other clause, except the complement of literal
Fall 2005 Costas Busch - RPI 11
( x 1 x 2 x 4 ) (x 1 x 2 x 4 ) ( x 1 x 2 x 3 ) ( x 2 x 3 x 4 )
x1 x2 x4
x1 x1
x2 x2
x4 x3
x2 x3 x4
Resulting Graph
Fall 2005 Costas Busch - RPI 12
( x 1 x 2 x 4 ) (x 1 x 2 x 4 ) ( x 1 x 2 x 3 ) ( x 2 x 3 x 4 ) 1
x1 1
x2 0 x1 x2 x4
x3 0
x1 x1
x4 1
x2 x2
x4 x3
x2 x3 x4
The formula is satisfied if and only if
the Graph has a 4-clique End of Proof
Fall 2005 Costas Busch - RPI 13
NP-complete Languages
We define the class of NP-complete
languages
Recursive (decidable)
NP
NP-complete
Fall 2005 Costas Busch - RPI 14
A language L is NP-complete if:
• L is in NP, and
• Every language in NP
is reduced to L in polynomial time
Fall 2005 Costas Busch - RPI 15
Observation:
If a NP-complete language
is proven to be in P then:
P NP
Fall 2005 Costas Busch - RPI 16
Recursive (decidable)
NP
NP-complete
Fall 2005 Costas Busch - RPI 17
Recursive (decidable)
NP
P
? NP-complete
Fall 2005 Costas Busch - RPI 18
An NP-complete Language
Cook-Levin Theorem:
Language SAT (satisfiability problem)
is NP-complete
Proof:
Part1: SAT is in NP
(we have proven this in previous class)
Part2: reduce all NP languages
to the SAT problem
in polynomial time
Fall 2005 Costas Busch - RPI 19
Take an arbitrary language L NP
We will give a polynomial reduction of L to SAT
Let M be the NonDeterministic
Turing Machine that decides L in polyn. time
For any string w we will construct
in polynomial time a Boolean expression (M ,w )
such that: w L (M ,w ) is satisfiable
Fall 2005 Costas Busch - RPI 20
All computations q0
of M on string w qi qj
depth
| w | n
n k
…
…
… accept
…
reject accept
(deepest leaf)
reject
Fall 2005 Costas Busch - RPI 21
Consider q0
an accepting qi qj
computation
depth
n k
…
…
… accept
…
reject accept
(deepest leaf)
reject
Fall 2005 Costas Busch - RPI 22
Computation path Sequence of
q0 Configurations
qi
initial state
qj
1: q0 1 2 n
2: 1 qi 2 n
…
qm
nk x : 1 l qa l1 n k
qa
accept state
accept
w 1 2 n
Fall 2005 Costas Busch - RPI 23
n
Machine M Tape
w
n k
n k
2n k
Maximum working space area on tape
during n time steps
k
Fall 2005 Costas Busch - RPI 24
Tableau of Configurations
1: # q0 1 2 n #
2: # 1 qi 2 n #
……
Accept configuration
x: # 1 2 3 qa l1 nk #
indentical rows
nk : # 1 2 3 qa l1 nk #
nk nk
2n 3k
Fall 2005 Costas Busch - RPI 25
Tableau Alphabet
C { # } {tape alphabet} {set of states}
{ # } {1 , , r } {q1 , , qt }
Finite size (constant)
Fall 2005 Costas Busch - RPI 26
For every cell position i, j
and
for every symbol in tableau alphabet s C
Define variable xi , j ,s
Such that if cell i , j contains symbol s
Then xi , j ,s 1
Else xi , j ,s 0
Fall 2005 Costas Busch - RPI 27
Examples:
nk 3
1: # q0 1 2 n #
2: # 1 qi 2 n #
x1,1,# 1 x 2,n k 3,q 1
i
x1,1, 0 x 2,n k 3,# 0
Fall 2005 Costas Busch - RPI 28
(M , w ) is built from variables x i , j ,s
(M ,w ) cell start accept move
When the formula is satisfied,
it describes an accepting computation
in the tableau
of machine M on input w
Fall 2005 Costas Busch - RPI 29
makes sure that every
cell cell in the tableau contains
exactly one symbol
cell
xi , j ,s xi , j ,s xi , j ,t
all i , j s C s ,t C
s t
Every cell contains Every cell contains
at least one symbol at most one symbol
Fall 2005 Costas Busch - RPI 30
Size of cell :
cell
xi , j ,s xi , j ,s xi , j ,t
all i , j s C s ,t C
s t
2
( 2n 3)k ( |C | | C |2 )
O (n 2k
)
Fall 2005 Costas Busch - RPI 31
start makes sure that the tableau
starts with the initial configuration
start x1,1,# x1,2,
x1,n k 1, x1,n k 2,q x1,n k 3,
0 1
x1,2n k 2, x1,2n k 2,#
Describes the initial configuration
in row 1 of tableau
Fall 2005 Costas Busch - RPI 32
Size of start :
start x1,1,# x1,2,
x1,n k 1, x1,n k 2,q x1,n k 3,
0 1
x1,2n k 2, x1,2n k 3,#
2n 3 O (n )
k k
Fall 2005 Costas Busch - RPI 33
makes sure that the computation
accept leads to acceptance
accept xi , j ,q
all i , j
all q F
Accepting states
An accept state should appear somewhere
in the tableau
Fall 2005 Costas Busch - RPI 34
Size of accept :
accept xi , j ,q
all i , j
all q F
(2n 3) O (n
k 2 2k
)
Fall 2005 Costas Busch - RPI 35
move makes sure that the tableau
give a valid sequence
of configurations
move is expressed in terms of
legal windows
Fall 2005 Costas Busch - RPI 36
Tableau
Window
a q1 b
q2 a c
2x6 area of cells
Fall 2005 Costas Busch - RPI 37
Possible Legal windows
a q1 b a q1 b
a b, R q2 a c a a q2
b c, L
q1 q2 a a q1 a b a
a a b a b q2
b a,R
Legal windows obey the transitions
Fall 2005 Costas Busch - RPI 38
Possible illegal windows
a b a a q1 b
a b, R a a a q1 a a
q1 b c, L q2 b q1 b
q2 b q2
b a,R
Fall 2005 Costas Busch - RPI 39
move (window (i, j) is legal)
all i, j
window (i,j) is legal:
j j j
i a q1 b i a q1 b i a a q1
q2 a c a a q2 a a b
((is legal) (is legal) (is legal))
all possible legal windows
in position (i , j )
Fall 2005 Costas Busch - RPI 40
j
i a q1 b
q2 a c
(is legal)
Formula:
xi , j ,a xi , j 1,q1 xi , j ,b
xi 1, j ,q2 xi 1, j 1,a xi 1, j 2,c
Fall 2005 Costas Busch - RPI 41
Size of move :
Size of formula for a legal window
in a cell i,j: 6
x Number of possible legal windows
in a cell i,j: at most | C |6
x Number of possible cells: (2n 3)
k 2
6 | C |6 (2n k 3)2 O (n 2k )
Fall 2005 Costas Busch - RPI 42
Size of (M ,w ) :
(M ,w ) cell start accept move
O (n 2k ) O (n k ) O (n 2k
) O (n 2k
)
O (n 2k
)
it can also be constructed in time O (n 2k )
polynomial in n
Fall 2005 Costas Busch - RPI 43
(M ,w ) cell start accept move
we have that:
w L (M ,w ) is satisfiable
Fall 2005 Costas Busch - RPI 44
Since,
w L (M ,w ) is satisfiable
and
(M ,w ) is constructed
in polynomial time
L is polynomial-time reducible to SAT
END OF PROOF
Fall 2005 Costas Busch - RPI 45
Observation 1:
The (M ,w ) formula can be converted
to CNF (conjunctive normal form) formula
in polynomial time
(M ,w ) cell start accept move
Already CNF
NOT CNF
But can be converted to CNF
using distributive laws
Fall 2005 Costas Busch - RPI 46
Distributive Laws:
P (Q R ) (P Q ) (P R )
P (Q R ) (P Q ) (P R )
Fall 2005 Costas Busch - RPI 47
Observation 2:
The (M ,w ) formula can also
be converted to a 3CNF formula
in polynomial time
a1 a2 al
conver
t
a1 a2 z1 (z1 a3 z 2 ) (z 2 a4 z 3 ) (zl 3 al 1 zl )
Fall 2005 Costas Busch - RPI 48
From Observations 1 and 2:
CNF-SAT and
3CNF-SAT are
NP-complete languages
(they are known NP languages)
Fall 2005 Costas Busch - RPI 49
Theorem:
If: a. Language A is NP-complete
b. Language B is in NP
c. A is polynomial time reducible to B
Then: B is NP-complete
Proof:
Any language L in NP
is polynomial time reducible to A.
Thus, L is polynomial time reducible to B
(sum of two polynomial reductions,
gives a polynomial reduction)
Fall 2005 Costas Busch - RPI 50
Corollary: CLIQUE is NP-complete
Proof:
a. 3CNF-SAT is NP-complete
b. CLIQUE is in NP (shown in last class)
c. 3CNF-SAT is polynomial reducible to CLIQUE
(shown earlier)
Apply previous theorem with
A=3CNF-SAT and B=CLIQUE
Fall 2005 Costas Busch - RPI 51