Transcript Document

On the Complexity of
Combinatorial Problems
Shmuel Wimer
Bar Ilan Univ., School of Engineering
Nov 2009
NP completeness
1
Modeling Algorithms: Turing Machine
A problem can be solved by an algorithm if and only if there exists some
Turing machine which halts for every input.
M:
 S , , , f , b, s0 , sY , sN  ,
where
S : A finite set of states.
s0 , sY and sN are called intial state, yes state and no state.
 : Finite set of tape symbols.
   is a proper subset of input symbols.
b     is called blank symbol .
f : Function f : S  sY , sN     S    1,1 , called transition function.
Nov 2009
NP completeness
2
M consits of: Infinite tape, divided into cells
, c  1 , c  0  , c 1 , c  2  ,
RW head located at one cell c  i  at each time t , h  t   i and h  0   1.
Each cell c  i  contains one symbol at a time,   i, t   . The input consists
of symbols xi residing in cells c  i  , 1  i  n, i.e.   i, 0   xi , 1  i  n, and
  i, 0   b otherwise.


Let s  t   S  sY , sN  and f s  t  ,   h  t  , t    p, q, d  . Then s  t  1  p
is the next state, the symbol at cell which head is positioned at t becomes
  h  t  , t  1  q and the head moves one cell step to h  t  1  h  t   d ,
leftwards if d  1 or rightwards if d  1. All other cells c  j  , j  h  t  do
not change, i.e.   j , t  1    j , t  . If s  t  1  sY , sN  the machine halts.
Nov 2009
NP completeness
3
A Turing machine M is said to solve a decision problem P if for every
instance of the problem defined by an input x1 , x2 ,
, xn the answer is yes
if and only if M halts at sY .
Though Turing machine is very slow, any problem solvable in polynomial
time on RAM machine is solvable in polynomial time on a Turing machine.
There’re many decision problems for which a polynomial time solution is
unknown, but with additional information a positive answer can be verified in
polynomial time. For instance:
• “is N not a prime number”, supplemented with a factor F.
• “Does a graph G(V,E) contain a Hamiltonian circuit”, supplemented
with a given circuit.
Nov 2009
NP completeness
4
Let us place some information in cells c  1 , c  2  , of the tape before M starts
computing. Sequence   1, 0  ,   2, 0  ,   g1 , g 2 ,  is called guess. If the time
allot to M is p  n  then the guess is no longer than p  n   1.
A decision problem D can be solved by a nondeterministic Turing machine in
polynomial time if there exists a polynomial p  n  such that if the answer to an
instance I of input length n is yes then there exists a guess for which M will halt
in p  n  in state SY , and if the answer is no then for every guess either M will not
halt at all or halts in state S N .
Nondeterministic Turing machine can be converted into algorithm (deterministic
Turing machine) by trying M on all |  | p n 1 possible guesses and see whether
any halts in SY , which unfortunately is exponential.
Nov 2009
NP completeness
5
P - Set of decision problems which can be solved by some polinomial
Turing machine
NP - Set of decision problems which can be solved by nondeterministic
polinomial Turing machine
Clearly, P  NP since we can always use a nondesterministic Turing
machine with the blank guess.
The question of whether P = NP or not hasn't been solved yet, but it is
believed that P  NP.
Nov 2009
NP completeness
6
NP-Completeness
Let D1 and D2 be decision problems. A polynomial reduction to D2 exists
( D1  D2 ) if there's a function f  I1   I 2 such that the answer of I1 w.r.t D1
is yes if and only if the answer of f  I1  w.r.t D2 is yes, and there exists a
polynomally bounded algorithm to compute f  I1  .
If D1  D2 and D2 can be solved in polynomial time so does D1. Let the algorithm
to produce I 2 be bounded by q  n  , where n is the length of I1. Let p  m  bound the
computation time of A2 , where m is input length of I 2  f  I1  . Since m  q  n  the
total computation time to solve D1 is bounded by q  n  + p  q  n   .
A problem D is NP - Complete (NPC ) if D  NP and for every D  NP, D  D.
Nov 2009
NP completeness
7
The Satisfiability Problem (SAT)
X   x1 , x2 ,
, xn  is a set of variables.
L   x1 , x2 ,
, xn , x1 , x2 ,
, xn  is the set of corresponding literals.
C  L is a clause.
A set of clauses C1 , C2 ,
, Cm is given.
Question: Is there an assignment of true/false values to x1 , x2 ,
, xn
such that every clause contains at least one true-valued literal.
Theorem : SAT is NPC.
Proof : SAT  NP since if a satisfying assignment is given, it is used as
a guess to M . It is then possible for M to verify the guess in a straight
forward task (though very tedious and cumbersome).
Nov 2009
NP completeness
8
By definition for every D  NP there exists polynomially bounded
nondeterministic Turing machine which solves it.
We'll show the existence of a polynomial reduction f , such that when
M , itsbounding polynomial p  n  and the input I of D are given, f  I 
constructs SAT instance, which is satisfiable if and only if M accepts I
in computation time p  n  at most.
f will simulate the operation of M on I . There will be eight sets of
clauses, the satisfiability of each assures that a certain condition of
M holds.
Nov 2009
NP completeness
9
For sake of simplicity we use the notation that s1 and s2 are the yes and
no states, so S  s1 , s2 , s3 ,
, sq  . Index k is used for states, 1  k  q.
For cells we use index i,  p  n   1  i  p  n   1. Index t is used for
time, 0  t  p  n  . Index j is used for tape symbols  =  0 ,  1 ,
, g ,
0  j  g.
Define a variable G  i, t , j  stating that tape symol in c  i  at time t
T
is  j as follows: G  i, t , j   
F
Nov 2009
  i, t    j 

otherwise 
NP completeness
10
Define a variable H  i, t  stating that head in on c  i  at time t as
follows:
T
H  i, t   
F
h t   i 

otherwise 
Define a variable S  t , k  stating that state at time t is sk as follows:
T
S t, k   
F
s  t   sk 

otherwise 
The set of variables for the satisfiability problem is:
G i, t, j  H i, t  S t, k 
Nov 2009
NP completeness
11
Let I  x1x2
xn
Condition 1: I is specified by c 1 , c  2  ,
while c  0  , c  n  1 ,
, c n,
, c  p  n 
are all blanks.
Corresponding set of clauses is (condition 1 holds if and only if S1
is satisfied):

S1  G  i, 0, j  |1  i  n and xi   j
 G i, 0, 0 | n  i  p  n 
G  0, 0, 0 
Condition 2: Initial state is s0 and h  0   1.
Corresponding set of clauses is: S2 
Nov 2009
S  0, 0,H  0,1
NP completeness
12
Condition 3: t , 0  t  p  n  , M is in one and only one state.
Corresponding set of clauses is:
S3 
S  t , 0  , S  t ,1 , , S  t , q 

t 0 
 k1  k2 S  t , k1 , S  t , k2 






Condition 4: t , 0  t  p  n  , each cell
c  i  ,  p  n   1  i  p  n   1, contains one and only one
tape symbol.
Corresponding set of clauses is:
S4 
Nov 2009
t
G  i, t , 0  , G  i, t ,1 , , G  i, t , g 

i
 j1  j2 G  i, t , j1 , G  i, t , j2 


NP completeness




13
Condition 5: t , 0  t  p  n  , the head is on one and only one
cell c  i  ,  p  n   1  i  p  n   1.
Corresponding set of clauses is:
S5 

 H   p  n   1, t  , H   p  n   2, t  ,

t
H  i1 , t , H  i2 , t 

i1 i2



, H  p  n   1, t  



Condition 6: The contents of c  i  can change from t to t  1
only if the head is on c  i  at t.
Corresponding set of clauses is:
S6 
Nov 2009
i
0t  p  n 
j
H i, t  , G i, t, j  , G i, t  1, j 
NP completeness
14
Condition 7: If s  t   S  sY , sN  then s  t  1 , h  t  1 and
  h  t  , t  1 are all adhering f . If s  t   sY , sN  then s  t  1  s  t  .
Corresponding set of clauses is:
S7 
i
t  p n 
0t  p  n 
S t,1, S t  1,1 ,S t, 2, S t  1, 2
k 1,2
j





S  t , k , H  i, t , G  i, t , j , S  t  1, k  


S  t , k , H  i, t , G  i, t , j , G  i, t  1, j  


 S  t , k , H  i, t , G  i, t , j , H  i  d , t  1 | f  sk ,  j    sk  ,  j  , d 


Nov 2009
NP completeness








15
Condition 8: s  p  n    sY .
Corresponding set of clauses: S8 
The set of clauses
8
i 1
S  p  n ,1.
Si is satisfiable if and only if there's a guess
for which M accepts I , by reaching at t  p  n  the yes state.
Consequently :
every NP decision problem is polynomially reducible to SAT.
Q.E.D
Nov 2009
NP completeness
16
3 Satisfiability Problem (3SAT)
• A sub problem of SAT where each clause contains exactly 3 literals
• It is yet NPC.
• Very useful since it is easier for many NP-Completeness proofs to
demonstrate reduction of 3SAT rather than SAT.
• In the 3SAT NP-Completeness proof we’ll demonstrate a polynomial
reduction of SAT.
• The definition of 3SAT is the following:
Input: A set of clauses, each consisting of exactly 3 literals.
Question: Is there truth values consistent assignment to the literals
in the clauses such that they are all satisfied?
Theorem: 3SAT is NPC.
Nov 2009
NP completeness
17
Proof : 3SAT  NP since if the set of clauses is satisfiable, there's a truth
assignment. We then build a Turing machine and use the truth assignment
as a guess. Though cumbersome, it is a straight forward task.
Consider the simple case where S1 is a set of clauses containing a clause of
four literals, namely, S1  a, b, c, d  S , and let x be a new supplementary
variable not in S1. Define S2  a, b, x
 x , c, d 
S . x can be set such that
S2 is satisfied if and only if S1 does.
Any clause a1 , a2 ,
, al  , l  3, can be replaced by a set of l  2 clauses
a , a , x  , x , a , x  , , x , a
1
2
1
1
3
2
i
i2
, xi 1 ,
l  3 supplementary variables x1 , x2 ,
,  xl 3 , al 1 , al  by introducing
, xl 3 whose setting is made such that
the original clause is satisfied if and only if the set of 3-length clauses does.
Nov 2009
NP completeness
18
If a1 =T or a2 =T , we assign x1 =x2 =
x1 =x2 =
=xl 3 =F . If al 1 =T or al =T , we assign
=xl 3 =T . If some ak =T , 2  k  l  1, we assign x1 =x2 =
and xk 1 =xk =
=xk 2 =T
=xl 3 =F . If the original clause is satisfied then one of the above
three cases must hold, and xi 's setting is each case ensures the satisfaction of all
clauses. If however original clauses is not satisfied there's no assignment of
x1 ,x2 ,
, xl  2 yielding the satisfaction of all 3-literal clauses.
The time required for the replacement of long clauses by 3-length ones
is polynomially bounded by the length of the input describing the original
set of clauses. The number of 3-length clauses is bounded by the number
of original literals and the total number of literals in the 3SAT problem is
three times at most than the original.
Q.E.D
Nov 2009
NP completeness
19
Three Dimensional Matching – 3DM
Let W , X and Y be three sets of same cardinality | W || X || Y | p.
Let M  W  X  Y be a three dimensional matching.
Question : Is there M   M such that | M  | p and for two triples of M 
 w, x, y  and  w, x, y  there exists w  w,
x  x and y  y ?
Theorem : 3DM is NPC.
Proof : Clearly 3DM is NP. We'll show that 3SAT is polynomialy reducible
to 3DM. Let input I of 3SAT consist of m clauses C  C1 , C 2 ,
n variables x1 , x2 ,
, C m  and
, xn .
f  I  the input of 3DM will consist of three sets of variable W , X and Y ,
and a matching M of triples  w , x, y  W  X  Y as explained below.
Nov 2009
NP completeness
20
Triples consists of three disjoint sets. The first called AC represents the
truth assignment consistency of the variables of 3SAT. AC will enforce a
variable get the same truth value in all the clauses it apppears, and get the
complementary truth value in all clauses where its complement appears.
A second set of triples called SC will ensure satisfaction of all 3SAT
clauses. Finally, there will be a set GC of triples (garbage collection)
enabling completion of matching once the other two conditions are met.
Sets of matchings AC , SC and GC are built from the sets W , X and Y defined
below. W   xij , xij |1  i  n, 1  j  m represents the appearence of xi in C j .
Though only 3m literals exist in clauses, these mn variables are not a concern.
Nov 2009
NP completeness
21
AC takes care for consistent truth assignment of xi accros all clauses. We first
define two sets A  aij |1  i  n, 1  j  m and B  bij |1  i  n, 1  j  m
which are then used to construct cyclic consistent assignment triples
 x , a , b  |1  j  m
  x , a , b  |1  j  m  x
ACi false 
ACitrue
ij
ij
ACi  ACi false
ij
i , j 1
ij
ij
im
, ai1 , bim .
ACitrue
Since bij is common to  xij , aij , bij  and  xij , ai , j 1 , bij  and ai , j 1 is common to
x ,a
ij
i , j 1
, bij  and  xi , j 1 , ai , j 1 , bi , j 1  , all triples of M   M corresponding to
truth assignment of xi (xi ) must be selected either from ACitrue or ACi false for all
clauses C j , 1  j  m. Finally, AC collects all ACi , AC 
Nov 2009
NP completeness
n
i 1
ACi .
22
To maintain the satisfaction of C j  C , we define the sets
S1  s1, j |1  j  m , S 2  s2, j |1  j  m , and
SC j 
 x , s
ij
1, j
, s2, j  | xi  C j
  x , s
ij
1, j
, s2, j  | xi  C j

Clearly, SC j contains exactly 3 triples from original 3SAT, of which exactly
one will be chosen for M   M since s1, j , s2, j are common to all, provided that
xij (xij ) hasn't been used in M 
AC. Finally, SC collects all SC j , SC 
m
j1
SC j .
 AC SC consumed nm  m of W 's 2mn variables. To cover the
rest m  n  1 variables we craete a supplementary set for grabage collection.
So far M 
G1   g1,k |1  k  m  n  1 , G2   g 2,k |1  k  m  n  1 , and
GC 
Nov 2009
 x , g
ij
1, k

, g 2,k  ,  xij , g1,k , g 2,k  |1  i  n, 1  j  m, 1  k  m  n  1
NP completeness
23
Thus each pair g1,k , g 2,k must be match with unique xij or xij that doesn't occur
in any triple of M 
 AC
SC . There are exactly m  n  1 such uncovered
variables, so the selection of all 2nm xij or xij will take palce.
Define M  AC
SC GC and set W , X , Y so W  X  Y  2mn, by
W   xij , xij |1  i  n, 1  j  m , X  A S1 G1 , and Y  B S 2
G2 .
M contains 2mn  3m  2m2 n  n  1 triples whose derivation from the 3SAT
instance is direct, and each triple of M is an element of W  X  Y as required.
Consequently M can be constructed in polynomial time.
It remains to show that M   M is a matching if and only if there exists a
truth assignment which satisfies C.
Nov 2009
NP completeness
24
M  being a matching implies the satisfaction of C by construction.
Conversely, let t :  xi , xi |1  i  n  T , F  be any truth assignment satisfying C.
We construct a matching as follows: Since C j is satisfied by t , the set of literals
Z j   xi , xi |1  i  n C j must contain one literal at least being set true by t.
Let z j  Z j . We then set
M 

true
AC
i
t  x  T
i
 
false
AC
i
t  x  F
i
   z , s
m
j 1
j
1, j

, s 2, j 
G
G  G is constructed to accommodate the rest xij and xij , not covered by the first
three set in M  definition. This is easily done by finding those literals and attching
corresponding g1, j and g 2, j .
Q.E.D
Nov 2009
NP completeness
25
Covering Problems – 3XC, XC and SC
Given subsets S  S1 , S 2 ,
a subset S   S , such that
, S n  of a universal set U , | Si | 3, 1  i  n, is there
Si S 
Si  U , and Si
S j  , for any Si  S  and S j  S  ?
Input : A collection C of 3-sets, all subsets of given universal set U .
Question : Is there a sub collection of C which is an exact cover of U?
Theorem : 3XC is NPC.
Proof : Obviously, 3XC  NP. We'll show that 3DM is polynomially reducible
to 3XC. Given W , X , Y and a matching M  W  X  Y of 3DM instance, we
assume w.l.g that they are pairwise disjoint. Otherwise, elements are renamed
(and M accordingly) to make them distinct of each other. Define
C  w, x, y |  w, x, y   M  and U  W
Nov 2009
NP completeness
X
Y.
26
It follows that there exists C   C which is an exact cover of U if and only if
there exists complete matching M   M .
Let M   M be a complete matching. Then
C   w, x, y |  w, x, y   M 
is an exact cover of U . Conversely, if C   C is an exact cover of U , then
M    w, x, y  | w, x, y  C 
is a complete matching.
Q.E.D
Exact cover (XC) problem is similar to 3XC except that set size is not
restricted. Since 3XC is a special instance of XC it follows that XC is NPC.
Nov 2009
NP completeness
27
Set covering (SC) problem is interested in the size of the cover rather than it
being exact cover.
Input : A Collection C of sets, all are subsets of a universal set U , and an
integer k .
Question : Is there C   C such that
S C 
S  U and |C  | k ?
Theorem : SC is NPC.
Proof : We'll show that 3XC is polynomially reducible to SC. The input C and
U of 3XC are used for SC, and k  | U | 3 . If | U | is not divisable by 3 then
the answer to 3XC is anyway no, so we are interested in the reduction when it
is divisable by 3.
Nov 2009
NP completeness
28
Let C  be exact cover of U , solving 3XC, then it is also a cover solving SC
since | C  | | U | 3  k .
If on the other hand C  is a cover solving SC with | C  | k , it follows from
every set containing exactly 3 elements of U that |U | 3k and sets of C  are
disjoint, hence being exact cover, implying a solution of 3XC.
Q.E.D
Nov 2009
NP completeness
29
Clique, Independent Set and Vertex Cover
V   V is an independent set of G V , E  if  u, v V ,  u, v  E.
V   V is a clique of G V , E  if  u, v V ,  u, v  E.
V   V is independent set of G V , E  iff it is a clique of G V , E  .
V  is a cover of G V , E  if
uV 
u, v  E.
V  is a vertex cover of G V , E  iff V  V  is an independent set
of G V , E  .
Nov 2009
NP completeness
30
Input : A graph G V , E  and an integer k | V | .
Question : Is there a vertex cover V   V such that | V  | k ?
Theorem : VERTEX COVER (VC) is NPC.
Proof : By transforming 3SAT to VC. Let U  u1 , u2 ,
C  C1 , C2 ,
, un  and
, Cm  be any instance of 3SAT. We construct a graph
G V , E  and an integer k | V | such that G has vertex cover not
greater than k iff C is satisfiable.
The idea in proof is to build G V , E  in bipartite fashion from two
sets of components. One representing U and other representing C.
There will be edges connecting between U and C components such
that proper selction of these edges implies VC implying 3SAT.
Nov 2009
NP completeness
31
For each ui  U there's a truth setting component Ti  Vi , Ei  with
two vertices Vi  ui , ui  connected by a single edge Ei  ui , ui .
Any VC will contain at least one of the vertices ui or ui in order to
cover the edge ui , ui  .
The other set of components S j  V j, E j  handles the satisfaction
testing of C j  C , 1  j  m, by allocating vertices V j  a1 j , a2 j , a3 j 
corresponding to the literals comprising C j . These are then connected
in a triangle by three edges E j 
Nov 2009
a
1j

, a2 j  , a2 j , a3 j  , a3 j , a1 j  .
NP completeness
32
Finally, Ti and S j components are connected in a bipartite fasion by 3m
edges as follows. Let x j , y j , and z j be the literals comprising C j . There


are three edges E j = a1 j , x j  , a2 j , y j  , a3 j , z j  emanating from C j and
connected to the corresponding vertices in the truth-setting components.
The VC instance is constructed as follows. G V , E  is defined by
V

n
V
i 1 i
 

V  and E 
j 1 j
m

n
i 1
Ei
 
E
j 1 j
m
 
m
j 1

E j ,
and setting k  n  2m.
It is easy to verify that the above construction f  I  takes polynomial
time.
Nov 2009
NP completeness
33
U  u1, u2 , u3 , u4  C  u1, u3 , u4 , u1, u2 , u4 
u1
u1 u2
u2 u3
u3 u4
a22
a21
a11
Nov 2009
u4
a31
a12
NP completeness
a32
34
Let V   V be VC of G such that |V  | k . In order for all E to be
covered, at least one vertex of each Ti and two vertices of each S j
must be in V , yielding a total of n  2m. We now intersect V  with
Ti and use this for truth assignment t : U  T , F  , setting t  ui   T
if ui V  and t  ui   F if ui V .
To assure that t : U  T , F  thus defined satisfies C , consider any
C j . It is connected (S j ) by 3 edges of E j to U . Since | V  V j | 2,
one edge must be covered by a vertex of some V  Vi , corresponding
to a literal that has been set true by the truth assinment, thus implying
the satisfaction of C j .
Nov 2009
NP completeness
35
Conversely, suppose that t : U  T , F  satisfies C. We'll choose the
vertices of V  as follows, and show that it constitues a cover. V  picks
one vertex from each Ti . If t  ui   T then ui V . Otherwise ui V .
All the edges in Vi are definitly covered. This also ensures that at least
one of the 3 edges in every E j is covered since every C j is satisfied.
Including in V  the vertices in S j incident to the other 2 edges of E j
will cover both these edges and all the edges of S j . In conclusion, we
have obtained a cover of size k  n  2m.
Q.E.D
Nov 2009
NP completeness
36
Hamiltonian Paths and Circuits
Input : A directed graph G V , E  and two vertices s and t.
Question : Is there a simple path from s to t , passingn through all
v  V  s , t ?
Theorem : Directed Hamilton path (DHP) is NPC.
Proof : By reduction of VC to DHP. Let G V , E  and an integer k | V |
be the input I to VC. We build G V , E   as follows.
1. VC covers e  u, v in G by choosing u, v, or both. We construct in G
an isolated path component which can be entered and left from a u -points
only, or v-points only (but not a mix of u -point and v-point).
Nov 2009
NP completeness
37
2. The selection of a vertex u in G by VC covers all its emanating
edges. It translates in G into connecting basic paths into track that
belongs to all the opposite vertices of u, such that track traversal in
G marks all the implied edges in G as being covered.
3. Finally, there is a "switch box" in G, consists of new k vertices,
enabling k jumps to tracks, representing the cover selection in G.
Let e  v,1 , e  v, 2  ,
, e  v, d  v   be the edges incident to v in G,
where d  v  is the degree of v. V  of G V , E   is defined by:
V   a0 , a1 ,
Nov 2009
, ak 
vV
v
1,i
, v2,i |1  i  d  v 
NP completeness
38
Vertices a0 , a1 ,
, ak are new symbols serving for cover selection.
v1,i and v2,i are the entering and leaving vertices of a path in G  of a
vertex connected to the opposite side of an incident edge, once v is
selected by VC in G. E  in G  consist of following three components.
E1 
 v
1,i
  v

, v2,i | v  V , 1  i  d  v 
2,i


, v1,i 1 | v  V , 1  i  d  v  .
Arcs are defined such that basic paths comprising entering and leaving
vertices in G of v in G are concatenated to construct a track traversing
vertices on the opposite side of the edges incident to v in G.
v1,1 v2,1
Nov 2009
v1,i v2,i
v1,i1 v2,i 1
NP completeness
v1,d vv2,d  v 
39
There are arcs in G representing an edge e  u, v  in G being both the i  th
incident at u (e  u, i ) and the j  th incident at v (e  v, j ), thus impling in G




connections as follows: E2  u1,i , v1, j , u2,i , v2, j | e  u, i   e  v, j  .
B
A
u1,i
v1, j
u2,i
v2, j
D
C
There are only 4 ways to visit u and v in G exactly once: enter A and


leave C passing trough u1,i , u2,i or enter A and leave C by detouring


through v1, j , v2, j . Entering B and leaving D is symmetric.
Nov 2009
NP completeness
40
Last part of E  arcs is connecting the ends of tracks built by E2 to the cover
selection vertices a0 , a1 ,
, ak  . It is accomplished by connecting entering
and leaving vertex of tracks to each of cover selection vertices, thus serving
as a passage between tracks.
E3 
 a , v  | 0  i  k , v V   v
i
1,1
1, d  v 


, ai | 0  i  k , v  V .
The set of arcs in is the merging E  E1 E2
E3
Let s  a0 and t  ak . This completes the reduction f  I  of VC into DHP.
The time required to construct f  I  is obviously polynomially bounded.
Nov 2009
NP completeness
41
Let C  v1, v 2,
, vk  be a cover in G. We assume w.l.g that |C | k since
a smaller cover can always converted to larger one. Vertex traversal in G
starts from a0  s and consumes the track corresponding to v1 by traversing
 v1
1,1
, v12,1 , v11,2 , v12,2 ,

,v11,d  v1 ,v12,d  v1 .
From v12,d  v1 we proceed to a1 and follow the track corresponding to v 2 in a
similar way, etc., untill the track corresponding to vk is consumed. We then
end by moving to ak  t.
The paths thus defined in G is simple by the way G was constructed, but
may not cover all V .
Nov 2009
NP completeness
42
Uncovered vertex v  V  inplies another uncovered "twin" v  V , stems




from v, v  E  (or v, v  E ) as shown in the detour figure. v and v
correspond to some "parent" v  V , having an opposite vertex in C. We

 

can therefore modify the path to join v, v (or v, v ), leaving it simple.
This is repeated untill V  is covered.
Converely, let P be Hamiltonian path in G . It must contain k tracks in G ,
to each we consider its corresponding "parent" vertex in G as a part of a
cover C  V . Hence | C | k .
Nov 2009
NP completeness
43
Consider an edge e  u, v  E. If both u's and v's corresponding G 
tracks are in P, e is covered (doubly). Otherwise, the only way of P
to cover vertices u1,i , u2,i , v1, j and v2, j is by either using u's track or
v's track, thus covering e by either u or v.
Q.E.D
Deciding whether a directed graph has a simple Hamiltonian circuit
(DHC) is also NPC. Reducing DHP to DHC is done by adding to G
 
 
a vertex a and edges t , a and a, s .
When G V , E  is undirected, deciding on whether Hamiltonian path
exists (HP) is also NPC.
Nov 2009
NP completeness
44
Input : A graph G V , E  and two vertices s and t.
Question : Is there a simple path in G V , E  , starting at s, ending at t ,
and passing through all the other vertices?
Theorem : HP is NPC.
Proof : Let the input I of DHP consist of G V , E  and two vertices
s and t. The idea in building f  I  is to construct G V , E   where
every vertex in V is translated into three successive vertices in V .
u
Nov 2009
v
w
u0
u1
u2
NP completeness
v0
v1
v2
w0
w1
w2
45
V   v0 , v1 , v2 | v V  E  v0 , v1 , v1 , v2  | v V 
u , v  | u, v  E
2
0
The two end points in G are s0 and t2 .
Consider a Hamiltonian path P in G from s to t. A Hamiltonian path P
in G is constructed as follows. It starts at s0 , ends at t2 , and uses the
arcs
v , v  , v , v  | v V  and u , v  | u, v   P.
0
1
1
2
2
0
Conversely, let P be Hamiltonian path in G, starting at s0 , and ending
at t2 . P necessairly includes s0 , s1 , s1 , s2  , t0 , t1 and t1 , t2  . All
the edges
v , v  ,v , v  | v V  must also be in
0
1
1
2
as otherwise some v1
doesn't belong to P.
Nov 2009
NP completeness
46
 
Whenever an esge u2 , v0  belongs to P, we add u, v to P. The path
thus created in G starts at s, ends at t , it is simple and passes through all
the other vertices of G.
Q.E.D
Nov 2009
NP completeness
47
Partition
Input : A finite set A and a size s  a   Z  for each a  A.
Question : Is there a subset A  A such that

aA
s  a =  aA A s  a  ?
Theorem : PARTITION is NPC.
Proof : PARTITION  NP, since nondeterministic algorithm needs only
guess A  A and check whether  aA s  a =  aA A s  a , which takes
polynomial time.
We'll show that 3DM  PARTITION.
Let W  w1 , w2 ,
, wq  , X  x1 , x2 ,
and M  m1 , m2 ,
, mk   X  Y  Z be any instance of 3DM.
Nov 2009
, xq  , Y   y1 , y2 ,
NP completeness
, yq  ,
48
We'll construct A  a1 ,
to m1 , m2 ,
, ak , ak 1 , ak  2  . Elements a1 ,
, ak  correspond
, mk  and their size s  ai  is set such that a certain number B
can be obtained as a sum of sizes of q elements iff they correspond to a
matching. s  ak 1  and s  ak  2  will enable the partition.
s  ai  , 1  i  k , is set by a binary representation comprising 3q groups,
each containing p  log 2  k  1  bits as shown below. Hence, binary
coding of s  ai  comprises 3 pq bits. The pq most significant correspond
to W , the second pq to X , and the pq least significant to Y .
w1 w2
Nov 2009
wq x1
xq y1
x
2
NP completeness
y2
yq
49
Given a triple mi  M , let f  i  , g  i  , and h  i  be functions assigning


the subscripts, i.e., mi  w f i  , xg i  , yhi  . In the corresponding groups
of p bits, rightmost is set 1 while the rest are set 0. The size is therefore
p 3q  f i 
p 2 q  g i 
p q hi 
s  ai   2 
2 
2 
. Since s  ai  is expressed by 3 pq
bits, its construction from the 3DM instance is polynomially bounded.
s  ai  corresponding to mi  M comprises three 1's in the 3 pq bit word.
One in most significant pq bits, one in middle pq bits, and one in least
significant pq bits, where 1's are positioned in rightmost bit of groups.
Nov 2009
NP completeness
50
Considering S   i 1 s  ai , there are at most k times where 1 can appear
k
in any group. Since the number of bits in any group is p  log 2  k  1  ,
the sum  aA s  a  of any subset A  ai |1  i  k cannot exceed k in
a group, so overflow will never happen (no carry to the next group).
A number B   j 0 2 pj is now defined, obtained uniqely by a word
3 q 1
where at each group there's 1 in the rightmost bit and 0 elsewhere.
Therefore, any subset A  ai |1  i  k will satisfy  aA s  a   B
iff M   mi | ai  A  M is a matching.
Nov 2009
NP completeness
51
The construction of A is completed by adding two elements ak 1 and
ak  2 and setting s  ak 1   2S  B and s  ak  2   S  B. Representation
of both needs no more than 3 pq  1 bits, thus can be constructed in
time polynomial in size of 3DM.
Let A  A satisfy  aA s  a =  aA A s  a  be a PARTITION. There
exists  aA s  a   S   2S  B    S  B   4S , yielding 2S sums on
each side of the partition, thus enforcing ak 1 and ak  2 to be in A and
A  A, since ak 1  ak  2  3S .
Nov 2009
NP completeness
52
The sum of sizes of the rest element on the side of ak 1 must therefore
equal B and the sum of sizes of rest elements on ak  2 side must equal
S  B, which is possible only if A corresponds to matching M   M .
Conversely, if M   M is a matching, setting A  ai | mi  M 
ak 1
forms the desired  A, A  A  PARTITION.
Q.E.D
Nov 2009
NP completeness
53
Proving NP Completeness
Proof by restriction : Known NPC problem  is special case of .
Example : EXACT COVER BY 3-SETS (X3C) was proved as NPC
by showing that 3-DIMENTIONAL MATCHING (3DM) is a special
case of X3C.
Example : KNAPSACK
INSTANCE: A finite set U , a "size" s  u   Z  and a "value" v  u   Z 
for each u U , a size constraint B  Z  and a value goal K  Z  .
Proof : Restrict to PARTITION by allowing only s  u   v  u  for
each u U and setting B  K  uU  s  u  2.
Nov 2009
NP completeness
54
Example: MINIMUM EQUIVALENT DIGRAPH
IMSTANCE: A directed graph G V , A  and K  Z  , K  A .
QUESTION: Is there a directed graph G V , A  , A  K , such that for every
vertex pair u and v in V , G contains a path from u to v if and only if G does.
Proof : Restrict to DIRECTED HAMILTONIAN CIRCUIT by allowing only
strongly connected directed graphs and setting K  V .
Example : MINIMUM COVER
INSTANCE: A collection C of subsets of a set S and K  Z  .
QUESTION: Is there a sub collection C   C , C   K , such that
cC 
c S?
Namely, is there a cover of S whose size doesn't exceed K?
Proof : Restrict to X3C by allowing only c  3 c C and K  S 3.
Nov 2009
NP completeness
55
Proof by local replacements : Pick some aspect of a known NP complete
problem and replace it in a uniform way by a new structure. Target problem
is built successively by local replacements.
Example : SAT was transfoemed into 3SAT. basic unit of SAT was a clause,
which was transformed into a collection of 3-size clauses in 3SAT. Changes
are local and independet of each other.
Example : PARTITION INTO TRIANGLES
INSTANCE: A Graph G V , E  with V  3q, q  Z  .
QUESTION: Is there a partition of V into q disjoint sets V1 , V2 ,
, Vq  of
three vertices each, Vi  vi1 , vi 2 , vi 3  , such that the inplied vertex pairs satisfy
v
i1
, vi 2  , vi1 , vi 3  , vi 2 , vi 3   E ?
Nov 2009
NP completeness
56
Theorem : PARTITION INTO TRIANGLES is NP complete.
Proof : We transform EXACT COVER BY 3-SETS (3XC) into
PARTITIONING INTO TRIANGLES. Every 3-set is associated with a
graph component featuring the triangles property. Let  xi , yi , zi  be the
ith 3-set of the exact cover. The following structure is then constructed:
ai 3
ai 9
ai 6
ai1
Nov 2009
ai 2
xi
ai 4
ai 5
yi
NP completeness
ai8
ai 7
zi
57
Let X , X  3q and C , a collection of 3-sets, be an arbitrary instance of
3XC. The graph G V , E  is defined by the components constructed for
every 3-set of 3XC instance. Let Ei be the edges of ith component. Then,
VX
C
i 1
a ,1  j  9, E  X
ij
C
i 1
Ei . G V , E  , V  3q  9 C  3q
vertices and E  18q edges. G V , E  can be constructed in polynomial
time from 3XC instance.
Notice that while the vertices  xi , yi , zi  may participate in several
graph components, ai1, ai 2 ,
, ai 9  are unique for a component.
We'll show that a subset c1 , c2 , , cq   C is exact cover of X iff there
exists a PARTITION INTO TRIANGLES of G V , E  .
Nov 2009
NP completeness
58
Suppose c1 , c2 , , cq  solves 3XC. The selection of 3-vertex disjoint
Vq in G V , E  is obtained in two different ways.
sets V  V1 V2
For ci  c1 , c2 ,, cq  the sets ai1 , ai 2 , xi  , ai 4 , ai 5 , yi  , ai 7 , ai 8 , zi 
and ai 7 , ai 8 , ai 9  are selected for PARTITION INTO TRIANGLES.
Otherwise, ai1, ai 2 , ai3 , ai 4 , ai5 , ai 6 and ai 7 , ai8 , ai9  are selected.
ai 3
ai 9
ai 6
ai1
Nov 2009
ai 2
xi
ai 4
ai 5
yi
NP completeness
ai8
ai 7
zi
59
It follows from the uniqueness of ai1 , ai 2 ,
, ai 9  in the construction and
from the uniueness of  xi , yi , zi  in 3XC that the 3-vertex sets as selected
are disjoint and cover V , thus imply a partition.
Conversely, let V  V1 , V2 ,
, Vq  is PARTITION INTO TRIANGLES.
It follows from the subgraphs structure and from the fact that a vertex is
unique in the partition that there are two exclusive triangle sets in every
structure (either the blue ones or the red ones) of which one and only one
is in use. Since vertices  xi , yi , zi  are selected exactly once, which happens
when the blue triangles are in use, exact cover is defined by choosing those
ci  C yielding V j  a j 3 , a j 6 , a j 9  for some 1  j  q.
Q.E.D
Nov 2009
NP completeness
60
Proof by component design : Constructed instance is a collection of components,
each performing some function in term of the given instance. NP completenes proof
of SATIFIABLITY is an examle. There, each component (clause group) reflects a
propery of a Turing machine.
3-DIMENTIONAL MATCHING (3DM), HAMILTONIAN PATH (HP) and
VERTEX COVER are another examples.
Example: MINIMUM TARDINESS SEQUENCING
Sceduling is usually aiming at sequencing such that all tasks will complete on
time. Sometimes, we may allow the completion of few tasks to slip.
INSTANCE: A set T of tasks with a partial order
, duration of every t  T
is one unit and has a specified deadline d  t   Z  , K  Z
Nov 2009
NP completeness
0 and K  T .
61
QUESTION: Is there a schedule  : T  0,1,
if t  t  and   t     t   whenever t
, T  1 such that   t     t  


t , such that t  T   t   d  t   1  K ?
Theorem : MINIMUM TARDINESS SEQUENCING is NPC.
Proof : We'll transform a graph CLIQUE problem into MINIMUM TARDINESS
SEQUENCING to simulate "proper" sequential clique construction, where an edge
of the clique is placed (scheduled) after both its end vertices are placed (scheduled).
Let G V , E  and J  V constitute an arbitrary CLIQUE instance. A corresponding
MINIMUM TARDINESS SEQUENCING instance is defined by tasks T  V
E.
The number of late tasks corresponds to edges that are being placed before their
end verices are placed, so K  E  J  J  1 2. K  0 if G contains J -vertex clique.
Nov 2009
NP completeness
62
Partial order is defined to ensure that an edge task is scheduled only after its end
vertices tasks are scheduled, hence t
t  if and only if t  V and t   E , and t is
an end vertex of edge t . Deadlines of edge tasks are set such that the entire tasks
to construct J -vertex clique, which requires a total of J  J  1 / 2  J  J  J  1 / 2
tasks, are scheduled successively, before any task related to other part of the graph
is scheduled.
 J  J  1 / 2 if t  E
d t   
if t  V
 V  E
tasks of placing J
tasks of placing J(J-1)/2
tasks of placing
tasks of placing rest
vertices of clique
edges of clique
rest |V - J| vertices
|E|- J(J-1)/2 edges
t 2009
0
Nov


t completeness
J J 1 2
NP
tV E
63
We'll show that the existance of a feasible schedule for T implies the existance of
a J -vertex clique in G. The schedule requires that all edges are placed until time
J  J  1 2 and it allows no more than E  J  J  1 2 tardy tasks, which can be
only edge tasks. Consequently, at least E   E  J  J  1 2   J  J  1 2 edge
tasks must be completed by time J  J  1 2. It leavs a room for at most J vertex
tasks, which is also the smallest possible in order to satify vertex-edge order.
Scheduling J  J  1 2 edge tasks and J vertex tasks within J  J  1 2 time and
satisfying vertex-edge order inplies that J -vertex clique has been found in G.
Conversely, given a J -vertex clique in G, a straight forward construction of a
schedue as depicted in the figure.
Q.E.D
Nov 2009
NP completeness
64
Nov 2009
NP completeness
65