Title: CSci 4011 Lecture 22
1CSci 4011
INHERENT LIMITATIONS OF COMPUTER PROGRAMS
2HARDEST PROBLEMS IN NP
Theorem A language B is NP-complete if
Definition A language B is NP-complete if
1. B ? NP
2. Every A in NP is poly-time reducible to
B (i.e. B is NP-hard)
2. A is NP-complete and A P B
If B is NP-Complete and P ? NP, then There is no
fast algorithm for B.
3REDUCTION STRATEGIES
A reduction by restriction shows that the
source problem is a special case of the target
problem.
For example, 3SAT P CNF-SAT because
every satisfiable 3CNF is also a satisfiable CNF.
Example. Prove 3SAT P 4SAT by restriction.
A 3CNF can be converted to an equivalent 4CNF by
repeating one literal in each clause.
4COLORING
COLOR ltG,kgt G is k-colorable
3COLOR G G is 3-colorable
Prove that 3COLOR P COLOR
5HAMILTONIAN PATHS
HAMPATH ltG,s,tgt G has a hamiltonian
path from s to t
6Let LPATH ltG,s,t,kgt G has a simple path
from s to t of length at least k
Prove that HAMPATH P LPATH
Let HAMILTONIAN G ?s,t such that G has a
hamiltonian path from s to t
Prove that HAMPATH P HAMILTONIAN
Let HAMCYCLE G G has a simple directed
cycle of length n
Prove that HAMPATH P HAMCYCLE.
7VERTEX COVER
VERTEX-COVER ltG,kgt G has a vertex cover of
size at most k
8INDEPENDENT SET
INDSET ltG,kgt G has an independent set of
size at least k
Prove that VERTEX-COVER P INDSET.
9SUBSET SUM
SUBSET-SUM lty1,, yn,tgt ?Sµ1,,n. Sj2S
yjt
Which of the following are in SUBSET-SUM?
lt1,3,5,7, 10gt
YES
lt19,11,27,4, 13gt
NO
lt19,11,27,4, 61gt
YES
10 lt(w1,v1),(wn,vn),W, Vgt ?S?1n so that
Si?Swi W and Si?Svi V
KNAPSACK
1lb, 20
½ lb 15
3 lbs 2000
15 lbs 500
50
11Theorem. SUBSET-SUM P KNAPSACK
Proof.
A subset sum instance is a knapsack where
the weights are equal to the values
Let (y1,,yn,t) lt(y1,y1)(yn,yn),t,tgt.
Then ?S. Si?S yi t iff ?S. Si?S yi t and
Si?S yi t, so lty1yn,tgt ? SUBSET-SUM iff
(y1yn,t)? KNAPSACK
12SET-COVER ltS1,,Sn,kgt ?i,Si?U and?i1k so
that Si1?Si2??Sik U
Which of the following are in SET-COVER?
lt1, 1,2, 2, 3, 2gt
YES
lt1,4, 1,2, 1,3, 4, 2gt
NO
lt1, 2, 1,2, 2gt
YES
Theorem. VERTEX-COVER P SET-COVER
Proof. A vertex cover instance is just a set
cover instance where every node is a set of edges.
13REDUCTION STRATEGIES
A reduction from A to B by local replacement
shows how to translate between units of A
and units of B.
Example. vertex cover units are vertices and
edges set cover units are elements and sets.
Example. CIRCUIT-SAT units are gates, CNFSAT
units are clauses, 3SAT units are 3-literal
clauses.
14GRADUATION
A transcript is a set of course numbers a student
has taken
A major consists of Pairs exactly one of
which must be taken Lists at least one course
of which must be taken
GRADUATION ltT,Mgt a subset of T satisfies M
For example T 1901A, 1902B, 1902A, 2011,
4041A, 4061, 4211 M 1901A,1901B,
1902A,1902B (4011,4041A,4041B),
(4211,4707), (4061)
15GRADUATION 2 NP
The subset is a proof that (T,M) 2 GRADUATION.
3SAT P GRADUATION
T 101, 102, 201, 202, 301, 302
(x1 Ç x2 Ç x3) Æ (x1 Ç x2 Ç x2) Æ (x2 Ç x3 Ç
x1)
M 101, 102, 201, 202, 301,
302
(101,201,302), (101,201,201),
(101,202,301)
16GRADUATION 2 NP
The subset is a proof that (T,M) 2 GRADUATION.
3SAT P GRADUATION
Let ? C1 Æ C2 Æ Æ Cm have variables x1xk
For each xi add classes i01 and i02 to T.
add pair (i01,i02) to M. For each Cj, we add a
triple to M if xi is a literal in Cj, the
triple includes i01. if xi is a literal in
Cj, the triple include i02.
17UHAMPATH
No HAM PATH
Undirected HAM PATH
A
B
A
B
C
D
C
D
E
F
E
F
UHAMPATH ltG,s,tgt G is an undirected
graph with a Hamiltonian path from s to t
18HAMPATH P UHAMPATH
Amid
Aout
A
B
Ain
C
D
E
F
19HAMPATH P UHAMPATH
A
B
C
D
E
F
20HAMPATH P UHAMPATH
f(G,s,t) (G,s,t) where
For each node u ? G add nodes uin, uout, umid
to G.
add edges uin,umid and umid,uout to G
For each edge (u,v)?G, add uout,vin to G
s sin, t tout.
If (G,s,t) ?HAMPATH, then (G,s,t)?UHAMPATH
(s,u,v,..,t) ! (sin,smid,sout,uin,umid,uout,vin,vm
id,vout,tout)
21HAMPATH P UHAMPATH
If (G,s,t) 2 UHAMPATH, then (G,s,t)2 HAMPATH
Let (sinv1,v2,,v3ntout) be the undirected path.
Claim for all i0, there exists u ? G so that
v3i1uin, v3i2umid, v3i3uout.
i0
If v2 ? smid, then no vismid. So v2smid, v3sout
Induction if v3i uout, then v3i1uin, so
v3i2umid.
The directed Hamiltonian path is (u1, u2, , un)
223SAT ?P SUBSET-SUM
We transform a 3-cnf formula ? into (y1yn, t)
? ? 3SAT ? (y1yn,t) ? SUBSET-SUM
The transformation can be done in time polynomial
in the length of ?
23Each variable and each clause result in two yis.
Each yi will have a digit for each clause and
variable.
x1
x2
C1
C2
C3
x1
(x1 Ç x2 Ç x2) Æ (x1 Ç x2 Ç x2) Æ (x1 Ç x2 Ç
x2)
x2
C3
C2
C1
243SAT ?P SUBSET-SUM
Let ? C1 Æ C2 Æ Cm have k variables x1xk.
We output y1 y2k 2m, each a km-digit number.
for each 1 j k for each 1 i m the
ith digit of y2j-1 is 1 if xj 2 Ci, else 0 the
ith digit of y2j is 1 if xj 2 Ci, else 0. digit
jm of y2j, y2j-1 is 1. For each 1 j m
y2k2j y2k2j-1 10j-1
Output t 11..1133..3