0% found this document useful (0 votes)
122 views90 pages

34.NP Completeness: Click To Add Text Hsu, Lih-Hsing

The document discusses NP-completeness and the classes P and NP of computational problems. It states that NP-complete problems are a class of problems whose status is unknown, as no efficient algorithms have been found but it also cannot be proven that efficient algorithms do not exist. The document provides an overview of polynomial-time algorithms and introduces the concept of reducing one problem to another to prove problems are NP-complete. It presents circuit satisfiability as the "first" NP-complete problem.

Uploaded by

Aarthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views90 pages

34.NP Completeness: Click To Add Text Hsu, Lih-Hsing

The document discusses NP-completeness and the classes P and NP of computational problems. It states that NP-complete problems are a class of problems whose status is unknown, as no efficient algorithms have been found but it also cannot be proven that efficient algorithms do not exist. The document provides an overview of polynomial-time algorithms and introduces the concept of reducing one problem to another to prove problems are NP-complete. It presents circuit satisfiability as the "first" NP-complete problem.

Uploaded by

Aarthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 90

34.

NP Completeness

Click
Hsu,toLih-Hsing
add Text
Computer Theory Lab.

P and NP
Non-formal description
 P: solvable polynomial time

 NP:

 nondeterministic polynomial time


 Verifiable in polynomial time by
deterministic Turing machine.

Chapter 34 P.2
Computer Theory Lab.

NP-complete
 NP-Complete: No polynomial-time
algorithm has yet been discovered for an
NP-complete problem, nor has anyone yet
been able to prove that no polynomial-time
algorithm can exist for any one of them.

Chapter 34 P.3
Computer Theory Lab.

Polynomial time algorithms: on inputs of size n, their


worst-case running time is O(n k ) .

It is natural to wonder whether all problems can be solved


in polynomial time. The answer is no. For example, the
Halting Problem.

Given a description of a program and a finite input, decide whether the program
Finishes running or will run forever.

Chapter 34 P.4
Computer Theory Lab.
Generally, we think of problems that are solvable by
polynomial-time algorithms are being tractable, and problems
that requires superpolynomial time are being intractable.

Polynomial Intractables

NP-Complete
Problem

Chapter 34 P.5
Computer Theory Lab.

The subject of this chapter, however, is an interesting class of


problems, called the “ NP-complete” problems, whose status
is unknown. No polynomial-time algorithm has yet been
discovered for an NP-computer problem, nor has anyone yet
been able to prove that no polynomial-time algorithm can
exist for any one of them. This so-called P ≠ NP question has
been one of the deepest, most perplexing open research
problems in theoretical computer science since it was first
posed in 1971.

Chapter 34 P.6
Computer Theory Lab.

NP-complete problem: status are unknown.

If any single NP-complete problem can be solved in


polynomial time, then every NP-complete problem has a
polynomial time algorithm.

To become a good algorithm designer, you must


understand the rudiments of the theory of
NP-completeness.

Chapter 34 P.7
Computer Theory Lab.

The difference between these problems


 Shortest vs. longest simple paths:
 Euler tour vs. hamiltonian cycle:
 2-CNF satisfiability vs. 3 CNF satisfiablility
 NP-completeness and the classes P and NP
 Overview of showing problems to be NP-
complete
 Decision problems vs. optimization problems

Chapter 34 P.8
Computer Theory Lab.

Reductions
Suppose that there is a different decision problem,
say B, that we already know how to solve in
polynomial time. Finally, suppose that we have a
procedure that transforms any instance  of A into
some instance  of B with the following
characteristics:
1.The transformation takes polynomial time.
2.The answer are the same. That is, the answer for  is
“yes” if and only if the answer for  is also “yes.”

Chapter 34 P.9
Computer Theory Lab.

yes yes
 Polynomial-time  Polynomial-time
reduction algorithm Algorithm to decide B
no no
Polynomial-time algorithm to decide A

We can call such a procedure a polynomial-time


reduction algorithm and, it provides us a way to
solve problem A in polynomial time:
1.Given an instance  of problem A, use a polynomial-
time reduction algorithm to transform it to an instance 
of problem B.
2.Run the polynomial-time decision algorithm for B on
the instance .
3.Use the answer for  as the answer for .

Chapter 34 P.10
Computer Theory Lab.

A First NP-complete problem


 Because the technique of reduction
relies on having a problem already
known to be NP-complete in order to
prove a different problem NP-complete,
we need a “first” NPC problem.
 Circuit-satisfiability problem

Chapter 34 P.11
Computer Theory Lab.
34.1 Polynomial time
Polynomial time solvable problem are regarded as tractable.
 Even if the current best algorithm for a problem has a
running time of (n100), it is likely that an algorithm with
a much better running time will soon be discovered.
 Problems for many reasonable models of computation,
can be solved in one model can be solved in polynomial
in another.
 Polynomial-time solvable problems has a nice closure
property.
f , g are polynomial
 f ( g) is also polynomial
Chapter 34 P.12
Computer Theory Lab.

Abstract Problems: An abstract problem Q is a binary


relation on a set of problem instances and a set S of
problem solutions.

Decision problems: those having yes/no solution.

Optimization problems: recast by imposing a bound on the


value to be optimized.

An encoding of a set S of abstract objects is a mapping e


from S to the set of binary string, for example:
Chapter 34 {0,1,2,3,…}={0,1,10,11,…} P.13
Computer Theory Lab.

We call a problem whose instance sets is the set of binary


strings a concrete problem.

We say that an algorithm solves a concrete problem in time


O( T ( n )) if when it is provided a problem instance i if
length n=|i|, the algorithm can produce the solution in at
most O( T ( n )) time.

Chapter 34 P.14
Computer Theory Lab.

A concrete problem is polynomial-time solvable if there


exists an algorithm to solve it in time O( n k ) for some
constant k.

The complexity class P is the set of concrete decision


problems that are solvable in polynomial time.

Chapter 34 P.15
Computer Theory Lab.

Abstract problem  concrete problem


e: I 
{ 0 ,1 } *
encoding

Problem input k complexity O(k)


unary k 11...1 ( k )
binary n   lg k  ( k )  ( 2 n )

Chapter 34 P.16
Computer Theory Lab.

We say that a function f : { 0 ,1 }*  { 0 ,1 } * is


polynomial-time computable if there exists a
polynomial-time algorithm A that given any x { 0 ,1 } * ,
produces as output f ( x ) .

Chapter 34 P.17
Computer Theory Lab.

For any set I of problem instances, we say that two


encodings e1 and e2 are polynomial related if there exist
two polynomial-time computable functions f12 and f 21
such that for any i  I , we have f12 ( e1( i ))  e2 ( i ) and
f21( e2 ( i ))  e1( i ) .

Chapter 34 P.18
Computer Theory Lab.

Lemma 34.1. Let Q be an abstract decision problem on


an instance set I, let e1 and e2 be polynomially related
encodings on I. Then e1( Q )  P if and only if e2 ( Q )  P .

Using reasonable encoding to neglect the distinction


between abstract and concrete problems.

Chapter 34 P.19
Computer Theory Lab.

A fo rm a l-la n g u a g e fra m e w o rk
A n a lp h a b e t  is a fin ite s e t o f s y m b o ls .

A la n g u a g e L o v e r  is a n y s e t o f s trin g s m a d e u p o f

s y m b o ls fro m  .
e m p ty s tr in g :  .

e m p ty la n g u a g e :  .

*


L e t L1 , L 2 b e tw o la n g u a g e s . W e c a n d e fin e

Chapter 34 P.20
Computer Theory Lab.

L 1  L 2 (union)
L 1  L 2 (intersect ion)
L (complemen t)
L 1 L 2  { x 1 x 2 | x 1  L 1 and x 2  L 2 }
(concatena tion)
The closure (Kleen star) of L :
L *  { }  L  L  L  ...
2 3

Chapter 34 P.21
Computer Theory Lab.

The set of instances of any decision problem Q is the set of


 * , where   { 0 ,1 } . Since Q is entirely characterized by
those problem instances that produces a 1 (yes) answer. We
can view Q as the language L over  * , where
L  { x   * | Q( x )  1 } .

Chapter 34 P.22
Computer Theory Lab.

Algorithm A accepts a string x { 0 ,1 } * if the given input


x, the algorithm output A(x)=1.

The language accepts by an algorithm A is the set


L  { x   * | A( x )  1 } .

The algorithm A rejects a string x if A(x)=0.

Chapter 34 P.23
Computer Theory Lab.

Even if language L is accepted by an algorithm A, the


algorithm will not necessarily reject a string x  L
provided as input to it. For example, the algorithm may
loop forever.

A language L is decided by an algorithm A if every binary


string is either accepted or rejected by the algorithm.

Chapter 34 P.24
Computer Theory Lab.

A language L is accepted in polynom ial tim e by an


algorithm A if for any length n string x  L , the algorithm
k
accepts x in tim e O ( n ) for som e constant k.

A language L is decided in polynom ial tim e by an


algorithm A if for any length n string x  { 0 ,1 } * , the
O ( n k)
algorithm decides x in tim e for som e constant k.
Chapter 34 P.25
Computer Theory Lab.

Example:
PATH PROBLEM:
PATH={<G,u,v,k> | G=(V,E) is an undirected graph,
u, v V , k  0 is an integer, and there is a path from u to v
whose length is at most k}.

Chapter 34 P.26
Computer Theory Lab.

 Can be accepted in polynomial time.


 Can be decided in polynomial time.

HALTING PROBLEM:
There exists an accepting algorithm, but no decision
algorithm exists.

Chapter 34 P.27
Computer Theory Lab.

We can informally define a complexity class as a set of


languages, membership in which is determined by a
complexity measure, such as running time, on an algorithm
that determines whether a string x belongs to language L.

Chapter 34 P.28
Computer Theory Lab.

We define the complexity class P as: P  { L  { 0 ,1 } *|


there exists an algorithm A that decides L in polynomial
time}.

Theorem 34.2. P  { L | L is accepted by a polynomial


algorithm}.

Chapter 34 P.29
Computer Theory Lab.

HAMILTONIAN CYCLE PROBLEM:


HAM_CYCLE={<G> | G is a hamiltonian graph}

verification: polynomial
decision problem: ?
Chapter 34 P.30
Computer Theory Lab.

34.2 Polynomial-time verification

PATH PROBLEM:
PATH={<G,u,v,k> | G=(V,E) is an undirected graph,
u, v V , k  0 is an integer, and there is a path from u to v
whose length is at most k}.

verification: linear time.


Decision problem: polynomial

Chapter 34 P.31
Computer Theory Lab.

naive algorithm:
input size: If we use the reasonable encoding of a graph as
its adjacency matrix, the number m of vertices is ( n ),
where n = |<G>| is the length of the encoding of G. There
are m! possible permutations of the vertices. Therefore the
running time is ( m !)  ( n !)  ( 2 n ) . This is not
a polynomial algorithm.

Chapter 34 P.32
Computer Theory Lab.

Verification algorithms:
A verification algorithm is a two-argument algorithm A,
where one argument is an ordinary input string x and the
other is a binary string y called a certificate. A
two-argument algorithm A verifies an input x if there exists
a certificate y such that A(x,y)=1. The language verified by
a verification algorithm A is
L  { x  { 0 ,1 } *| y  { 0 ,1 } * s.t . A( x , y )  1 } .

Chapter 34 P.33
Computer Theory Lab.

The complexity class NP


The complexity class NP is the class of languages that can
be verified by a polynomial-time algorithm. More precise, a
language L belongs to NP if and only if there exists a
two-input polynomial-time algorithm A and a constant c
such that
L  { x { 0 ,1 } * | there exists a certificate y with
| y|  O(| x|c ) such that A(x,y)=1}.
 NP   (HAM_CYCLE  NP.)
 P  NP .
Chapter 34 P.34
Computer Theory Lab.

Problem:
1. P  NP?
2. Complexity class co-NP
co  NP  { L | L  NP } .
NP  co  NP?
3. Obviously P  NP  co  NP .
P  NP  co  NP ?

Chapter 34 P.35
Computer Theory Lab.

NP=co-NP
P=NP=co-NP
P

P
NP co-NP

P  NP  co  NP

P
NP co-NP

P  NP  co  NP
Chapter 34 P.36
Computer Theory Lab.

34.3 NP-completeness and reducibility


NP-completeness problem: if any one NP-complete
problem can be solved in polynomial time, then every
problem in NP has a polynomial-time solution, that is
NP=P.

Chapter 34 P.37
Computer Theory Lab.

Reducibility:
ax  b  0
ax 2  bx  c  0

Chapter 34 P.38
Computer Theory Lab.

A language L1 is polynomial-time reducible to a language


L2 , written L1  P L2 if there exists a polynomial-time
computable function f : { 0 ,1 }*  { 0 ,1 } * such that for all
x  L1 if and only if f ( x )  L2 . We call the function f
the reduction function, and a polynomial algorithm F that
computes f is called a reduction algorithm.

Chapter 34 P.39
Computer Theory Lab.

f
{ 0 ,1 }* { 0 ,1 }*

L1 L2

Chapter 34 P.40
Computer Theory Lab.

Lemma 34.3. If L1 , L2 { 0 ,1 } * are languages


such that L1  P L2 , then L2  P implies L1  P .

yes, f ( x)  L2 yes, f ( x)  L1

x f (x)
F A2
no, f ( x)  L2
no, f ( x)  L1
A1

Chapter 34 P.41
Computer Theory Lab.

NP-Completeness
A language L { 0 ,1 } * is NP-complete if
1. L  NP , and
2. L'  P L for every L'  NP

Chapter 34 P.42
Computer Theory Lab.

 If a language L satisfies property 2, but not necessarily


property 1, we say that L is NP-hard.

 We also define NPC to be the class of NP-complete


language.

Chapter 34 P.43
Computer Theory Lab.

Theorem 34.4. If any NP-complete problem is


polynomial-time solvable, then NP=P. If any problem is
not polynomial-time solvable, then all NP-complete
problem are not polynomial-time solvable.

Proof. By Lemma 34.3.

NPC
NP

Chapter 34 P.44
Circuit satisfiability Computer Theory Lab.

x1 1
1
1
1
x2 1
0 1
1 1
1
0
1
1 1 Satisfiable
x3
0 1
1

x1

x2

Not Satisfiable!
x3
Chapter 34 P.45
Computer Theory Lab.

Circuit-satisfiability problem: Given a boolean


combinational circuits composed of AND, OR, or NOT
gates, is it satisfiable?

CIRCUIT_SAT={<C> | C is a satisfiable boolean


combinational circuit}.

Chapter 34 P.46
Computer Theory Lab.

Lemma 34.5. The circuit-satisfiability problem belongs


to the class NP.

Lemma 34.6. The circuit-satisfiability problem is NP-hard.

Proof. L  P CIRCUIT _ SAT L  NP.

Theorem 34.7. The circuit-satisfiability problem is


NP-Complete.

Chapter 34 P.47
Computer Theory Lab.

Input bits

C0 A Program Counter Aux Machine State x y working storage

C1 A Program Counter Aux Machine State x y working storage

C2 A Program Counter Aux Machine State x y working storage

C T(n) A Program Counter Aux Machine State x y working storage

0/1 output
Chapter 34 P.48
Computer Theory Lab.

34.4 NP-Completeness Proof

Lemma 34.8. If L is a language such that L'  P L for


some L'  NPC , then L is NP-hard. Moreover, if L  NP
then L  NPC .

Chapter 34 P.49
Computer Theory Lab.

Method for proving a language L is NPC:


1. Prove L  NP .
2. Select a known NPC language L'
3. Describe an algorithm that computes a function f
mapping every instance of L' to an instance of L.
4. Prove that the function f satisfies x  L' if and only if
f ( x )  L for all x { 0 ,1 } * .
5. Prove that the algorithm computing f runs in polynomial
Chapter 34 time. P.50
Computer Theory Lab.

Formula satisfiability:
An instance of SAT is a boolean formula  composed of
1. boolean variables: x1 , x2 ,...
2. boolean connectives: any boolean function with one or
two input and one output
3. parentheses

Chapter 34 P.51
Computer Theory Lab.

SAT={< > |  is a satisfiability formula}


  (( x1  x2 )  (( x1  x3 )  x4 ))  x2
x1  0 , x2  0 , x3  1, x4  1
  (( 0  0 )  (( 0  1 )  1 ))  0
Example:
 (1  (1  1 ))  1
 (1  0 )  1
1

Chapter 34 P.52
Computer Theory Lab.

Theorem 34.9 Satisfiability of boolean formula is


NP-complete.
Proof.
 SAT  NP
 CIRCUIT _ SAT  P SAT
x1

x5 x8
x2

x6 x 10

x9

x3 x7
x4
Chapter 34 P.53
Computer Theory Lab.

  x10  ( x4  x3 )  ( x5  ( x1  x2 ))
 ( x6  x4 )  ( x7  ( x1  x2  x4 ))
 ( x8  ( x5  x6 ))  ( x9  ( x6  x7 ))
 ( x10  ( x7  x8  x9 ))

Chapter 34 P.54
Computer Theory Lab.

3-CNF satisfiability
 literal
 conjunction normal form (CNF)
 3-conjunction normal form (3-CNF)

( x1  x1  x2 )  ( x3  x2  x4 )
 (x1  x3  x4 )

Chapter 34 P.55
Computer Theory Lab.

Theorem 34.10. Satisfibility boolean formula in 3-CNF


is NP complete.
Proof.
 3  CNF  SAT  NP
 SAT  P 3  CNF  SAT

Chapter 34 P.56
  (( x1  x2 )  (( x1  x3 )  x4 )  x4 Computer Theory Lab.

y1

y2

x4

y3 y4
 

y5

x1 x2

y6

x4

Chapter 34 x1 x3 P.57


Computer Theory Lab.

  y1  ( y1  ( y2   x4)  ( y2  ( y3  y4)
 ( y3  (x1  x2)  ( y 4   y5)
 ( y5  ( y6  x4)  ( y6  ( x1  x 3)

Chapter 34 P.58
Computer Theory Lab.

1  y1  ( y2  x2 )
Truth Table 
1  ( y1  y2  x2 )  ( y1  y2  x2 )
 ( y1  y2  x2 )  (y1  y2  x2 )
De Morgan rule 
1  (y1  y2  x2 )  (y1  y2  x2 )
 (y1  y2  x2 )  ( y1  y2  x2 )

Chapter 34 P.59
Computer Theory Lab.

| Ci|  3 Ci

| Ci | 2

Ci  l1  l2  (l1  l2  p)  (l1  l2  p)

| Ci|  1

Ci  l  ( l  p  q )  ( l  p  q )
( l  p  q )  ( l  p  q )
Chapter 34 P.60
Computer Theory Lab.

34.5 NP-Complete Problems

Chapter 34 P.61
Computer Theory Lab.

CIRCUIT-SAT

SAT

3CNF-SAT

Clique HAM-CYCLE

VERTEX COVER TSP

SUBSET-SUM

Chapter 34 P.62
Computer Theory Lab.

34.5.1 The clique problem


A clique in a undirected graph G = (V,E) is a subset
V '  V of vertices, each pair of which is connected by an
edge in E. The size of a clique is the number of vertices it
contains. The clique problem is the optimization problem
of finding a clique of maximum size in a graph.

Chapter 34 P.63
Computer Theory Lab.

CLIQUE={<G, k> |G is a graph with clique size k}

2 |V |
naïve algorithm: ( k   )
 k

Chapter 34 P.64
Computer Theory Lab.

Theorem 34.11. The clique problem is NP-complete.


Proof.
 clique  NP
 3  CNF  SAT  P clique

  ( x1  x2  x3 )  (x1  x2  x3 )


 ( x1  x2  x3 )

Chapter 34 P.65
Computer Theory Lab.

C1  x1  x2  x3

x1 x2 x3

x1 x1

x2 x2

x3 x3

C2  x1  x2  x3 C3  x1  x2  x3
Chapter 34 P.66
Computer Theory Lab.

   C1  C2 ... Ck

r s (1) rs
 ( vi , v j )  E  r s
(2) li  l j

 clique size k

Chapter 34 P.67
Computer Theory Lab.

34.5.2 The vertex-cover problem


 A vertex cover of an undirected graph G=(V,E) is a
subset V '  V such that if ( u, v )  E then u V ' or
v V ' (or both).
 The vertex cover problem is to find a vertex cover of
minimum size in a given graph.
 VERTEX-COVER={<G, k> | graph G has a vertex cover
of size k}.

Chapter 34 P.68
Computer Theory Lab.

Theorem 34.12. The vertex-cover problem is NP-complete.


Proof.
 VERTEX  COVER  NP
 CLIQUE  P VERTEX  COVER

Chapter 34 P.69
Computer Theory Lab.

u v u v

z w z w

y x y x

Chapter 34 P.70
Computer Theory Lab.

34.5.3The hamiltonian-cycle problem

Theorem 34.13. The hamiltonian cycle problem is


NP-complete.
Proof.
 HAM  CYCLE  NP
 3CNF  SAT  P HAM  CYCLE

 kinds of wedges
Chapter 34 P.71
  ( x1  x2  x3 )  ( x1  x2  x3 )  ( x1  x2  x3 ) Computer Theory Lab.

b1 ,1

x 1'

b1 ,2
A e1
e1
B
x 1''
A
b1 ,3

b1 ,4

b2 ,1 A

A
x 2'

b2 ,2
e2
B A e2

b2 ,3
A x 2''

b2 ,4
A
b3 ,1
A

x 3'
b3 ,2 e3
e3
B
b3 ,3
A x 3''

b3 ,4

Chapter 34 P.72
Computer Theory Lab.
b1,3 x 3'

b1 ,3

b1,4
b1 ,4
A x 3'

e3
b3 ,3
A x 3''

b3,3
b3 ,4

b3,4 x 3''

Chapter 34 P.73
Computer Theory Lab.

34.5.4 The traveling-salesman problem

TSP={<G, c, k> | G = (V, E) is a complete graph, c is a


function from V  V into Z, k  Z , and G has a traveling
salesman tour with cost at most k}.

u v
4

3 2
1
1

x w
Chapter 34
5 P.74
Computer Theory Lab.

Theorem 34.13
 The hamiltonian cycle problem is NP-
complete.

Chapter 34 P.75
Computer Theory Lab.

Proof.
 First, show that HAM-CYCLE belongs to NP.
 We now prove that VERTEX-COVER p HAM-
CYCLE, which shows that HAM-CYCLE is NP-
complete.
 Given an undirected graph G=(V,E) and an
integer k, we construct an undirected graph
G’=(V’,E’) that has a hamiltonian cycle iff G
has a vertex cover of size k.

Chapter 34 P.76
Computer Theory Lab.

widget

[u,v,1] [v,u,1] [u,v,1] [v,u,1] [u,v,1] [v,u,1] [u,v,1] [v,u,1]

[u,v,2] [v,u,2]

[u,v,3] [v,u,3]
Wuv Wuv Wuv Wuv
[u,v,4] [v,u,4]

[u,v,5] [v,u,5]

[u,v,6] [v,u,6] [u,v,6] [v,u,6] [u,v,6] [v,u,6] [u,v,6] [v,u,6]

(a) (b) (c) (d)

Chapter 34 P.77
The reduction of an instance of Computer Theory Lab.

the vertex-cover problem to an


instance of the hamiltonian-cycle
problem.
 (a) An undirected graph G with a vertex of
size 2, consisting if the lightly shaded vertices
w and y.
 (b) the undirected graph G’ produced by the
reduction, with the hamiltonian path
corresponding to the vertex cover shaded.
 The vertex cover {w,y} corresponds to edges
(s1,[w,x,1]) and (s2,[y,x,1]) appearing in the
hamiltonian cycle.
Chapter 34 P.78
Computer Theory Lab.
w x

(a)

z y

(b)

[w,x,1] [x,w,1] [x,y,1] [y,x,1] [w,y,1] [y,w,1] [w,z,1] [z,w,1]

Wuv Wuv Wuv Wuv

[w,x,6] [x,w,6] [x,y,6] [y,x,6] [w,y,6] [y,w,6] [w,z,6] [z,w,6]


Chapter 34 P.79
Computer Theory Lab.

Three types of edges in E’


1. Edges in widget.
2. {([u,u(i),6],[u,u(i+1),1]) : 1  i 
degree(u)-1}
3. {(sj,[u,u(1),1]) : uV and 1  j  k} 
{(sj,[u,u(degree(u)),6]) : uV and 1  j 
k}

Chapter 34 P.80
Computer Theory Lab.

The reduction performed in


polynomial time
 |V’| = 12|E| + k
 12|E| + |V|

 |E’| = (14|E|) + (2|E| -|V|) + (2k|V|)


= 16|E| + (2k-1)|V|
 16|E| + (2|V|-1)|V|

Chapter 34 P.81
Computer Theory Lab.

 The transformation from graph


G to G’ is a reduction.
 That is, G has a vertex cover of
size k iff G’ has a hamiltonian
cycle.

Chapter 34 P.82
Computer Theory Lab.

Theorem 34.14. The traveling salesman problem is


NP-complete.
Proof.
 TSP  NP
HAM  CYCLE  P TSP

Chapter 34 P.83
Computer Theory Lab.

34.5.5 The subset-sum problem


S={1,4,16,64,256,1040,1041,1093,1284,1344}
t=3754
S' ={1,16,64,256,1040,1093,1284}

SUBSET-SUM={<S, t> | there exists a subset S'  S such


that t   s
sS'

Chapter 34 P.84
Computer Theory Lab.

Theorem 34.15
 The subset-sum problem is NP-
complete.

Chapter 34 P.85
Computer Theory Lab.

Proof.
 First, show that SUBSET-SUM is in NP.
 We now show that 3-CNF-SAT p SUBSET-
SUM.
 Given a 3-CNF formula  over variables x1,
x2,…, xn with clauses C1, C2,…, Ck, each
containing exactly three distinct literals.
 The reduction algorithm constructs an
instance <S,t> of the subset-sum problem
such that  is satisfiable iff there is a subset
of S whose sum is exactly t.
Chapter 34 P.86
Computer Theory Lab.

Example
 The formula in 3-CNF is  = C1  C2 
C3  C4, where C1 = (x1  ¬x2  ¬x3), C2
= (¬x1  ¬x2  ¬x3), C3 = (¬x1  ¬x2 
x3), and C4 = (x1  x2  x3).
 A satisfying assignment of  is <x1 = 0,
x2 = 0, x3 = 1>.

Chapter 34 P.87
Computer Theory Lab.

The reduction of 3-CNF-SAT to


SUBSET-SUM C 4 has no ¬x1
x1 x2 x3 C1 C2 C3 C4
v1 = 1 0 0 1 0 0 1
v1’ = 1 0 0 0 1 1 0
v2 = 0 1 0 0 0 0 1 C4 has x2
v2’ = 0 1 0 1 1 1 0
v3 = 0 0 1 0 0 1 1
v3’ = 0 0 1 1 1 0 0
s1 = 0 0 0 1 0 0 0
s1 ’ = 0 0 0 2 0 0 0
s2 = 0 0 0 0 1 0 0
s2 ’ = 0 0 0 0 2 0 0
s3 = 0 0 0 0 0 1 0
s3 ’ = 0 0 0 0 0 2 0
s4 = 0 0 0 0 0 0 1
s4 ’ = 0 0 0 0 0 0 2
t = 1 1 1 4 4 4 4
Chapter 34 P.88
Computer Theory Lab.

The reduction performed in


polynomial time
 The set S contains 2n+2k values, each
of which has n+k digits, and the time to
produce each digit is polynomial in n+k.
 The target t has n+k digits, and the
reduction produces each in constant
time.

Chapter 34 P.89
Computer Theory Lab.

 3-CNF formula  is satisfiable


iff there is a subset S’  S
whose sum is t.

Chapter 34 P.90

You might also like