You are on page 1of 72

NP-completeness

Class of hard problems


Outline
 Introduction
 Problems and Languages
 Turing machines and algorithms
 P and NP
 Satisfiability problem
 Reduction
 Other NP-complete problems

prithviraj_cs@rediffmail. NP-complete Problems 2


com
Problems
 A problem can be defined as a mapping from
the instance to the answer.
 Examples:
 Shortest path problem
{<graph G, node u, node v>} → {a shortest path P}
 0/1 Knapsack problem
{<set S of objects, capacity C>} → {the maximum
value}
 Closest-pair-of-points problem
{<set P of points>} → {<point q, point r>, which is
the closest pair of points in P}.
 Satisfiable problem
{<boolean formula>} → {T, F}
prithviraj_cs@rediffmail. NP-complete Problems 3
com
Abstract problems
A set of instances

A set of solutions

prithviraj_cs@rediffmail. NP-complete Problems 4


com
Decision Problems
 A decision problem is a problem whose
answer is either “yes” or “no”.

 Example: Satisfiable problem


{<boolean formula>} → {T, F}

 Any problem can be described in term of


a decision problem.

prithviraj_cs@rediffmail. NP-complete Problems 5


com
Reformulate Problems as Decision
Problems
 Shortest path problem
 {<graph G, node u, node v, int k>} → {T, F}

 The answer is T iff there is no path between


u and v, which is shorter than k.

 0/1 Knapsack problem


 {<set S of objects, capacity C, value V>} →
{T, F}
 The answer is T iff there is no selection of
objects fitted in the sack which yields higher
value than V.
prithviraj_cs@rediffmail. NP-complete Problems 6
com
Problems
 An encoding of a problem is a mapping from the set
of instances of the problem to a set of strings.

 Example: shortest path


 The encoding of <graph G, node u, node v, path p>
in the Shortest path problem is a string which is used
to describe G, u, v, and p.
 G can be described by a string of its adjacency matrix.
 u and v can be described by two strings, indicating the
node labels.
 p can be described by a sequence of node in the path.

prithviraj_cs@rediffmail. NP-complete Problems 7


com
Abstract/ Concrete problems
A set of instances

Mapping
Abstract (encoding) Concrete
problem
problem
Mapping
(encoding)

A set of solutions

prithviraj_cs@rediffmail. NP-complete Problems 8


com
Encoding of Problems
 Is X a prime ?
f:{X |X>0 and is a binary number}→{Y,N}
f(x) = Y if X is prime
f(x) = N otherwise

 Is a 3-CNF expression X satisfiable?


f:{X | X is a 3-CNF expression} → {Y, N}
f(x) = Y if X is satisfiable
f(x) = N otherwise

prithviraj_cs@rediffmail. NP-complete Problems 9


com
Why encoding is important?
 Encoding determines the instance size.
 Example: an integer n
 n encoded as one number
=> instance size = 1
 n encoded as binary number
=> instance size = log2 n
 n encoded as unary number
=> instance size = n

prithviraj_cs@rediffmail. NP-complete Problems 10


com
Problems and
Languages
Problems
 Let Σ be an alphabet.
 A language over Σ is a set of strings created
from symbols in Σ .
 B={0,1}* is the set of all binary strings.
 {ω ∈Σ ∗ω is a palindrome} is a language over B.

 A yes-instance (or no-instance) is an instance


whose answer is “yes” (or “no”).
 An instance must be either a yes- or a no-
instance.

prithviraj_cs@rediffmail. NP-complete Problems 12


com
Problems
 A decision problem can be encoded in a
language {ω ∈Σ ∗|ω is an encoding of a
yes- instance}.
 The shortest path problem can be encoded as
{e(G, u, v, p>)| p is the shortest path between u
and v in the graph G}.

prithviraj_cs@rediffmail. NP-complete Problems 13


com
Turing Machines
Turing machines (TM)
 A Turing machine is a machine which takes
a string on its input tape, and decides
whether to accept or to reject the string.
 A Turing machine contains
 A finite-state control with
 A start state
 A halt state
 Transition function: state x symbol → state x symbol x
{R,L}
 A tape with a Read/Write head which can move
left and right.

prithviraj_cs@rediffmail. NP-complete Problems 15


com
Deterministic/ Nondeterministic Turing
machines
 Difference
 A transition is deterministic or nondeterministic.
 What is nondeterminism?
 Given a state of a machine/program, there is
more than one possible next step.
 Examples
 Deterministic: functions.
 Nondeterministic: relations.

prithviraj_cs@rediffmail. NP-complete Problems 16


com
Example of a DTM
s

∆ /@,R

/∆
,L
1/∆ ,R
p1 q1
,R

0/∆ ,R

@/∆ ,R
/∆
, L ∆
/0 ,L
0 /1

1/1,R
0/0,R
1
p4 p2 q2
0/
∆ /∆ ,L

∆ /1,L
,L

p3 h
prithviraj_cs@rediffmail. NP-complete Problems 17
com
How a DTM works

s
∆ /∆ ,L
∆ /@,R
1/∆ ,R
p1 q1 ∆
∆ ∆1
@ 0 ∆0 ∆0 ∆
1 ∆0 ∆0 ∆0 ∆
∆ /∆ ,R
0/0,L 0/∆ ,R
@/∆ ,R
1/1,L
0/0,R
p4 p2 1/1,R q2
∆ /1,L
∆ /∆ ,L
0/∆ ,L On the input 0001000,
p3 h the TM halts.
prithviraj_cs@rediffmail. NP-complete Problems 18
com
How a DTM works

s
∆ /∆ ,L
∆ /@,R
1/∆ ,R
p1 q1 ∆ ∆0 ∆0 ∆0 ∆
@ 0 ∆0 ∆0 ∆0 ∆
∆ /∆ ,R
0/0,L 0/∆ ,R
@/∆ ,R
1/1,L
0/0,R
p4 p2 1/1,R q2
∆ /1,L On the input 0000000,
∆ /∆ ,L
0/∆ ,L the TM hangs.
p3 h
prithviraj_cs@rediffmail. NP-complete Problems 19
com
Example of NTM
 Let L={ww| w∈{0,1}*}
,R r0 0/
@ 0/0,R
L
0, , L /∆ ,R
s /
0 /1 ,L
1 /∆
@ 1/1,R

q0 t0
R
∆ /@,

,L 0/ ,R
0/0,L /∆ ∆
1/1,L 0 ,L /∆

∆ /@,
v L p 1/
∆ /∆ ,R
u ∆
@/∆ ,L
h
∆ ,L /∆
,L ∆ ,R
0/0,R 1/
1/1,R

0/0,L q1 @ t1
1/1,L /∆ ,R
∆ /∆ ,L ,R @
1/ 0/0,R
r1 1/1,R

prithviraj_cs@rediffmail. NP-complete Problems 20


com
Accept/Decide
 Let T be a Turing machine.
 For a string ω over Σ ,
 T accepts ω iff T halts on ω with output “1”.
 T rejects ω iff T halts on ω with output “0”.
 T hangs on ω iff T dose not halts on ω .

 For a language L over Σ ,


 T accepts L iff, for any string ω in L, T accepts ω .
 T decides ω iff
 for any string ω in L, T accepts ω , and

 for any string ω inL, T rejects ω .

prithviraj_cs@rediffmail. NP-complete Problems 21


com
Time complexity
 A language L is accepted/decided in O(f(n))
by a Turing machine T if, for any length-n
string ω in L, ω is accepted/decided in
k·f(n) by a Turing machine T, for some
constant k.

 A language L is accepted/decided in
polynomial time by a Turing machine T if, L
is accepted/decided in O(nk) by a Turing
machine T, for some constant k.

prithviraj_cs@rediffmail. NP-complete Problems 22


com
Church-Turing Thesis
 If there is a Turing machine deciding a
problem π in O(f), then there is an
algorithm solving π in O(f).
 Turing machine ≡ algorithm

prithviraj_cs@rediffmail. NP-complete Problems 23


com
Complexity classes
Class of P
 If π is a problem in P, given any instance I
of π ,
 there is an algorithm which solves I in O(nk), or
 there is a Turing machine which accepts e(I) in
O(nk) steps,
where n is the size of e(I) and k is a
constant.

 What does this mean?


 If π is in P, π is easy because it can be solved in
polynomial time.

prithviraj_cs@rediffmail. NP-complete Problems 25


com
Class of NP
 If π is a problem in P, given any instance I
and any certificate C of π ,
 there is an algorithm which verifies, in O(nk),
that C is the answer of I, for any C and I.
 there is a Turing machine which verifies, in O(nk),
that C is the answer of I, for any C and I.
 there is a nondeterministic Turing machine which
accepts e(I), in O(nk), for any I.
where n is the size of e(I) and k is a
constant.
What does this mean?
 If π is in NP, π is not necessarily easy because
it can only be verified in polynomial time.

prithviraj_cs@rediffmail. NP-complete Problems 26


com
problems
 Can be solved in  Cannot be solved in
polynomial time polynomial time
 Prove by showing the  Prove by showing that
algorithm. there is no polynomial-
time algorithm.
 Can verify the answer
in polynomial time.
 Can usually be solved
by an exponential-time
algorithm.
 Brute-force algorithm:
try every possible
answers.

prithviraj_cs@rediffmail. NP-complete Problems 27


com
Class of co-NP
 L is in co-NP ifL is in NP.

NP P co-NP

prithviraj_cs@rediffmail. NP-complete Problems 28


com
Reduction
Is X more difficult than Y?
Reduction
 Let L1 and L2 be languages over Σ 1 and Σ 2,
respectively. L1 is (polynomial-time) reducible to L2,
denoted by L1≤ L2, if there is a TM M computing a
function f: Σ 1*→Σ 2
*
such that w∈L1 ↔ f(w)∈L2 in
polynomial time.

 Let P1 and P2 be problems. P1 is (polynomial-time)


reducible to P2, denoted by P1≤ P2, if there is an
algorithm computing a function f: Σ 1*→Σ 2* such that
w is a yes-instance of P1 ↔ f(w) is a yes-instance of P2
in polynomial time.

prithviraj_cs@rediffmail. NP-complete Problems 30


com
Meaning of Reduction
P1 is reducible to P2
if ∃ DTM computing, in polynomial time, a function
f: Σ 1*→Σ 2* such that w is a yes-instance of P1 ↔ f(w)
is a yes-instance of P2.
 If you can map yes-instances of problem A to yes-
instances of problem B, then
 we can solve A in polynomial time if we can solve
B in polynomial time.
 it doesn’t mean we can solve B in polynomial time
if we can solve A in polynomial time.

prithviraj_cs@rediffmail. NP-complete Problems 31


com
Example of
Reductuion
Satisfiability problem (SAT)
A B C A∧~B∨C ~A∨~C α
 Given a Boolean
expression α , is α 0 0 0 0 1 0
satisfiable?
0 0 1 1 1 0
0 1 0 0 1 0
 (A∧~B∨C)∧(~A∨~C)∧B∧~C
is not satisfiable. 0 1 1 1 1 0
1 0 0 1 1 0
1 0 1 1 0 0
1 1 0 0 1 0
1 1 1 1 0 0

prithviraj_cs@rediffmail. NP-complete Problems 33


com
3CNF-SAT Problem
 Given an expression α in 3CNF, is α
satisfiable?
 Given an expression α in 3CNF, is there a
truth assignment of propositions in α which
makes α true?
 Example:
 α =(P∨Q∨R)∧(P∨Q∨R)∧(P∨S∨R)∧(P∨S∨R)
 α is satisfiable when
 P=t, Q=f, R=f, S=t or
 P=f, Q=f, R=f, S=t

prithviraj_cs@rediffmail. NP-complete Problems 34


com
Clique or Complete Subgraph
 A graph G=(V,E) has a clique if there is W⊆ V such
that for all nodes a and b in W, there is an edge
between a and b.

C
B

A E F

prithviraj_cs@rediffmail. NP-complete Problems 35


com
Clique Problem
 Given a graphG=(V,E) and an integer k, is there a
clique of size k in G?
 Example: Is there a clique of size 3, 4, or 5, in the
graph below?

C
B

A E F

prithviraj_cs@rediffmail. NP-complete Problems 36


com
3CNF-SAT ≤ Clique
Proof:
To prove that 3CNF-SAT ≤ Clique,
 Find a function f such that
a 3CNF expression α is satisfiable ↔
a graph G has a clique of size k, where
<G,k>=f(α ) and
 there is a TM computing f in polynomial time.

f can be defined as follows:


Let α = (γ 11∨γ 12∨γ 13)∧(γ 21∨γ 22∨γ 23)∧…∧(γ n1∨γ n2∨γ n3)
f(α ) = <G,n>, where G=(V, E),
 V={γ | 0<i<n+1, 0<j<4}, and
ij
 E={(γ , γ
ij km)| i≠k and γ ij ≠~γ km}

prithviraj_cs@rediffmail. NP-complete Problems 37


com
exp.
(P∨Q∨R)∧(P∨S∨R)∧(P∨S∨R)
~Q
P R

~P P

~S
S

~R ~R

prithviraj_cs@rediffmail. NP-complete Problems 38


com
3CNF-SAT ≤ Clique (cont’d)
 Show α is satisfiable↔G has clique of size n
 Let G has a clique of size n.
 From the definition of G, there is no edge
between vertices
 in the same disjunctive clause, and
 representing a literal and its negation.
 A link between two nodes means that the two
literals can be true at the same time, and they are
in different disjunctive clauses.

prithviraj_cs@rediffmail. NP-complete Problems 39


com
Satisfiability and Clique
(P∨Q∨R)∧(P∨S∨R)∧(P∨S∨R)
~Q
P R

~P P

~S
S

~R ~R

prithviraj_cs@rediffmail. NP-complete Problems 40


com
Satisfiability and Clique
(P∨Q∨R)∧(P∨Q∨R)∧(P∨Q∨R)∧(P∨Q∨R)
Q
P R

~P
P

Q
Q

R
~R
~P ~R
Q

prithviraj_cs@rediffmail. NP-complete Problems 41


com
Satisfiability and Clique
(P∨Q∨R)∧(P∨Q∨R)∧(P∨Q∨R)∧(P∨Q∨R)
Q
P R

~P
P

Q
Q

R
~R
~P ~R
Q

prithviraj_cs@rediffmail. NP-complete Problems 42


com
3CNF-SAT ≤ Clique (cont’d)
 There is a TM computing f in polynomial time.

prithviraj_cs@rediffmail. NP-complete Problems 43


com
Properties of
Reductions
Reflexivity of reduction
Theorem:
Let L be a language over Σ . L ≤ L.
Proof:
Let L be a language over Σ .
Let f be an identity function from Σ *→Σ *.
Then, there is a TM computing f.
Because f is an identity function, w∈L ↔
f(w)=w∈L.
By the definition, L ≤ L.

prithviraj_cs@rediffmail. NP-complete Problems 45


com
Property of reduction
Theorem:
Let L1 and L2 be languages over Σ .

If L1≤ L2, thenL1≤ L2.


Proof:
Let L1 and L2 be languages over Σ .

Because L1≤ L2, there are a function f such that w∈L1


↔ f(w)∈L2, and a TM T computing f in polynomial
time.
w∈L1 ↔ f(w)∈L2.

By the definition,L1≤ L2.


prithviraj_cs@rediffmail. NP-complete Problems 46
com
Transitivity of reduction
Theorem: Let L1, L2 and L3 be languages over Σ .
If L1 ≤ L2 and L2 ≤ L3, then L1 ≤ L3.
Proof: Let L1, L2 and L3 be languages over Σ .

There is a function f such that w∈L1 ↔ f(w)∈L2, and a TM T1


computing f in polynomial time because L1≤ L2.

There is a function g such that w∈L2 ↔ g(w)∈L3, and a TM T2


computing g in polynomial time because L2 ≤ L3.

w∈L1 ↔ f(w)∈L2 ↔ g(f(w))∈L3, and T1→T2 computes g(f(w)) in


polynomial time .

By the definition, L1 ≤ L3.

prithviraj_cs@rediffmail. NP-complete Problems 47


com
P/NP
Theorem: If L2 is in P/NP, and L1≤ L2, then L1 is also P/NP.
Proof:
Let L1 and L2 be languages over Σ , L1≤ L2, and L2 be in P/NP.

Because L2 is in P/NP, there is a DTM/NTM T2 accepting L2 in


polynomial time.

Because L1≤ L2, there is a DTM T1 computing a function f such that


w∈L1 ↔ f(w)∈L2 in polynomial time.

Construct a DTM/NTM T=T1→T2. We show that T accepts L1 in


polynomial time.
 If w∈L1, T1 in T computes f(w)∈L2 and T2 in T accepts f(w), in
polynomial time.
 If w∉L1, T1 in T computes f(w) ∉L2 and T2 in T does not accept f(w)
in polynomial time.

Thus, L1 is also in P/NP.

prithviraj_cs@rediffmail. NP-complete Problems 48


com
NP.
Theorem:
If L2 is in co-NP, and L1≤ L2, then L1 is also in co-NP.

Proof:
Let L1 and L2 be languages over Σ , L1≤ L2, and L2 be
in co-NP.

Because L2 is in co-NP,L2 is in NP.

Because L1≤ L2,L1≤ L2. Then,L1 is in NP.

Thus, L1 is co-NP.
prithviraj_cs@rediffmail. NP-complete Problems 49
com
NP-completeness
NP-completeness
 A language (or problem) L is NP-hard if, for
any language L' in NP, L' ≤ L.

 A language (or problem) L is NP-complete if


it is in NP and is NP-hard.

prithviraj_cs@rediffmail. NP-complete Problems 51


com
Why interested in NP-complete
problem
 Implication on the problem “is P=NP ?”
 If an NP-complete problem is in P, then
P=NP.
 Why?
 If L is NP-complete, any language in NP is
reducible to L.
 Since L is in P, any language in NP is reducible to
a language in P.
 Then, any language in NP is in P.

prithviraj_cs@rediffmail. NP-complete Problems 52


com
Lemma
If L is a language such that L’ ≤ L for some
L’ ∈ NPC, then L is NP-hard.
Moreover, if L ∈ NP, then L ∈ NPC.
Proof
Since L’ is NP-complete, for all L’’ ∈ NP, we
have L’’ ≤ L’ .
Because L’ ≤ L, L’’ ≤ L by transitivity.
Then, L is NP-hard.
If L ∈ NP, we also have L ∈ NPC.

prithviraj_cs@rediffmail. NP-complete Problems 53


com
Ground Reduction
SAT is NP-complete
SAT is NP-complete
 To prove that SAT is NP-complete:
 Prove SAT is in NP
 Prove any language in NP is reducible to SAT.

 SAT is in NP: Informal proof


 Given a certificate which is a truth assignment of
propositions which makes the expression true,
there is an algorithm that can verify the answer
in polynomial time.

prithviraj_cs@rediffmail. NP-complete Problems 55


com
SAT is NP-complete (cont’d)
Prove any language in NP is reducible to SAT.

Proof:

Let L be any language in NP.

Then, there is an NTM T which accepts L in


polynomial time p(n), where n is the input size.

To show that L ≤ SAT, we find a function f such


that x ∈ L ↔ f(x) ∈ SAT.

That is, to find a function f such that x ∈ L ↔ f(x) is


satisfiable.

prithviraj_cs@rediffmail. NP-complete Problems 56


com
SAT is NP-complete (cont’d)
Proof (cont’d):

That is, to find a function f such that T accepts x ↔ f (x) is


satisfiable.

Let f (x)=g1(x)∧g2(x)∧g3(x)∧g4(x)∧g5(x)∧g6(x)∧g7(x).

f (x) describes the sequence of configuration changes which


leads to the halt state of T.

f(x) contains propositions Qi,j , Hi,k , and Si,k,j .

Qi,j : T is in state qj after i moves.

Hi,k : T’s tape head is on square k after i moves.

Si,k,j : Symbol σ j is on square k after i moves.

prithviraj_cs@rediffmail. NP-complete Problems 57


com
SAT is NP-complete (cont’d)
Proof (cont’d):
g1(x): the initial configuration of T at the beginning.
g2(x): accepting configuration of T after N steps.
g3(x): possible transitions of T.
g4(x): hanging configuration.
g5(x): describe that T is in exactly one state at a time.
g6(x): describe that each square of the tape contains
exactly one symbol.
g7(x): describe that change can only made on the
tape square on which the tape head is located.

prithviraj_cs@rediffmail. NP-complete Problems 58


com
SAT is NP-complete (cont’d)
Proof (cont’d):
g1(x): describe the initial configuration of T at the beginning.

n N

Q0,0 ∧ H0,0 ∧ S0,0,0 ∧ ∧ S0,k,i ∧ ∧ S0,k,0


k
k=1 k=n+1

∆ 0 1 1 0 1 ∆ ∆ ∆ ∆ ∆ ∆ ∆ ∆ ∆ ∆ ∆

q0

prithviraj_cs@rediffmail. NP-complete Problems 59


com
SAT is NP-complete (cont’d)
Proof (cont’d):

g2(x): describe accepting configuration of T


after N steps.

QN,a

ha

prithviraj_cs@rediffmail. NP-complete Problems 60


com
SAT is NP-complete (cont’d)
Proof (cont’d):

g3(x): describe possible transitions of T.

For each transition


δ(qj, σ l)= (qt1 , σ z1 , D1), δ(qj, σ l)= (qt2 , σ z2 , D 2)

(Qi,j ∧Hi,k ∧Si,k,l )→((Qi+1,t1 ∧ Hi+1,d1 (k) ∧ Si+1,k,z1 )


V (Qi+1,t2 ∧ Hi+1,d2 (k) ∧ Si+1,k,z2 ))

prithviraj_cs@rediffmail. NP-complete Problems 61


com
SAT is NP-complete (cont’d)
Proof (cont’d):

g4(x): describe hanging configuration.

For each transition δ(qj, σ l)= ø

(Qi,j ∧ Hi,k ∧ Si,k,l) → (Qi+1,j ∧ Hi+1,k ∧ Si+1,k,l)

prithviraj_cs@rediffmail. NP-complete Problems 62


com
SAT is NP-complete (cont’d)
Proof (cont’d):
g5(x): T is in exactly one state at a time.

For each time i and states qj0 , qj1 , qj2 , …, qj0 ≠ qj1 ≠
qj2 ≠ … :

(Qi,j0 v Qi,j1 v Qi,j2 v …)


 At least one state

(~Qi,j0 v~Qi,j1 )∧(~Qi,j1 v~Qi,j2 )∧(~Qi,j0 v~Qi,j2 )∧…


 Never two state at the same time
prithviraj_cs@rediffmail. NP-complete Problems 63
com
SAT is NP-complete (cont’d)
Proof (cont’d):
g6(x): state that each square of the tape
contains exactly one symbol.
For each time i, square k, and symbols σ 0, σ 1,
σ 2, …, σ 0 ≠ σ 1 ≠ σ 2 ≠ … :
(Si,k,0 v Si,k,1 v Si,k,2 v …)
 At least one symbol in a cell

(~Si,k,0v~Si,k,1) ∧ (~Si,k,1v~Si,k,2) ∧ (~Si,k,0v~Si,k,2) ∧…


 Never two symbols in a cell at the same time

prithviraj_cs@rediffmail. NP-complete Problems 64


com
SAT is NP-complete (cont’d)
Proof (cont’d):
g7(x): state that change can only made on the
tape square on which the tape head is
located.

For each i, k, and l :


(~Hi,k ∧ Si,k,l) → (Si+1,k,l)

Hi,k v ~Si,k,l v Si+1,k,l

prithviraj_cs@rediffmail. NP-complete Problems 65


com
SAT is NP-complete (cont’d)
Proof (cont’d):
From the definition of f, f(x) is true iff T
accepts x.
f(x) can be computed in polynomial time.

Thus, SAT is NP-complete.

prithviraj_cs@rediffmail. NP-complete Problems 66


com
3CNF-SAT is NP-complete
First, show 3CNF-SAT is in NP.
Let α be a 3CNF expression, and
truth assignments C be a certificate for α .

There is an algorithm to verify that α is


true under the assignments C, by
substituting the value of each literal and
evaluating the expression.

This algorithm takes polynomial time of the


length of α .
prithviraj_cs@rediffmail. NP-complete Problems 67
com
3CNF-SAT is NP-complete
Second, show SAT ≤ 3CNF-SAT.
Let α be a Boolean expression.
We will construct a 3CNF expression f(α ) such that
f(α ) is satisfiable iff α is satisfiable.

To create f(α ):
(A) Create an abstract syntax tree of α so that
internal nodes are logical operators ∧, v, ~, →, or ↔
, and leaf nodes are literals (x or ~x).

Then, create β , from the abstract syntax tree which


is satisfiable iff α is satisfiable.
prithviraj_cs@rediffmail. NP-complete Problems 68
com
3CNF-SAT is NP-complete
α = ((p → q) ∧ (((~s v r) ↔ (q ∧ ~r)) v ~s)
∧:y1

→:y2 v:y3

p q ↔ :y4 ~s

β = y1 ∧ (y1 ↔ (y2 ∧ y3)) v:y5 ∧:y6

∧ (y2 ↔ (p → q )) ~s r q ~r
∧ (y3 ↔ (y4 v ~s))
∧ (y4 ↔ (y5 ↔ y6))
∧ (y5 ↔ (~s v r ))
∧ (y6 ↔ (q ∧ ~r))
α is satisfiable iff β is satisfiable.
prithviraj_cs@rediffmail. NP-complete Problems 69
com
3CNF-SAT is NP-complete
(B) Convert β into CNF.
P ↔ Q is transformed to (P → Q) ∧ (Q → P).
P →Q is transformed to ~P v Q.
~(P v Q) is transformed to ~P ∧ ~Q.
~(P ∧ Q) is transformed to ~P v ~Q.

γ = (y1 ↔ (y2 ∧ y3)) =(y1 → (y2 ∧ y3)) ∧ ((y2 ∧ y3) → y1)


=(~y1 v (y2 ∧ y3)) ∧ (~y2 v ~y3 v y1)
= (~y1 v y2) ∧ (~y1 v y3) ∧ (y1 v ~y2 v ~y3)
= (~y1 v y2 v y3) ∧ (~y1 v y2 v ~y3) ∧ (~y1 v y2 v y3)
∧ (~y1 v ~y2 v y3) ∧ (y1 v ~y2 v ~y3)

γ ≡ β

prithviraj_cs@rediffmail. NP-complete Problems 70


com
3CNF-SAT is NP-complete
f(α ) = γ , and f(α ) is satisfiable iff α is satisfiable.

Next, we need to show that f is computable in polynomial time.


In step (A):
the abstract syntax tree can be created in polynomial time of
the length of α ,
the expression β can be created also in polynomial time of
the number of node in the tree and the length of α , which is
also a polynomial time of the length of α .
In step (B):
γ can be created, using Boolean logic identities, in
polynomial time of the length of β , which is also a
polynomial time of the length of α .
That is, SAT ≤ 3CNF-SAT.

prithviraj_cs@rediffmail. NP-complete Problems 71


com
CLIQUE is NP-complete
Proof:

3CNF-SAT is NP-complete.

3CNF-SAT ≤ CLIQUE.

CLIQUE is NP-complete.

prithviraj_cs@rediffmail. NP-complete Problems 72


com

You might also like