Title: Computer Science 500 Theory of Computation Spring 1999 April 8
1Computer Science 500Theory of ComputationSpring
1999April 8
2?p1, NP, poly-time verifiable another view
?p1
L? iff L x ? w p(w,x)
Polynomial (in x) time decidable predicate
3NP-harddefinition
A language L is NP-hard iff L in NP, L
ltp L
A
4NP-completedefinition
A language L is NP-complete iff L is in NP
L is NP-hard
5Theorem (Cook-Levin)SAT is NP-complete
Proof We already know SAT is in NP. So, we
only need to show that SAT is NP-hard. Let L be
any language in NP. We demonstrate a poly-time
reduction from L to SAT
6Proof Idea
w ? L N has an accepting path on w ? a legal,
accepting tableau for N computing on w ? ?i ?
?a ? ?c ? ?m has a satisfying assignment
7Proof SAT is NP-hard
Idea Given (N,w), imagine a tableau
Ns configuration
c1,1 c1,2 c1,3c1,4 c1,nk c2,1
c2,2 c2,3 c2,4
c2,nk . . . cnk,,1 cnk,2 cnk,3 cnk,4
cnk,nk
1 2 nk
time
8Proof SAT is NP-hard
If N accepts w, then there is a legal tableau
that looks like this
Current state and implicit location of the
tape head
Ns configuration
q0 w1 w2 wn U U c2,2 c2,3 c2,4
c2,nk1 c3,2 c3,3 c3,4
c3,nk1 any accept
configuration
1 2 nk
time
9For 0lt i,j lt nk and m in ??U Q U , let
boolean variable xi,j,m correspond to whether
or not ci,j m I.e. For every i,j, exactly
one value xi,j,m True For other values of
m, xi,j,m False
10Proof SAT is NP-hard
Constructing ?
Each line in the tableau is a valid move for N
??w? ?cell AND ?move AND ?start AND ?accept
The last line is a valid accept configuration
For each i,j exactly one value xi,j,m equals 1
The first line of the tableau is the initial
configuration
11?cell
?cell ANDi,j (ORm xi,j,m (ANDm neq m xi,j,m
))
Each cell ci,j in the tableau contains exactly
one of Q, ?,
12?start
?start x1,1, AND x1,2,q0 AND x1,3,w1 ..
AND x1,n2,wn AND x1,n3,U AND x1,nk-1,U AND
x1,nk,
13?final
?final ORj xnk,j,qA
14Definition 3-SAT
3-SAT ?(x1, x2 xn) ? is in SAT ? C1
AND C2 AND Cn where Ci ?i1 OR
?i2 OR ?i3, and each ?ij xk or xk for
some k
Conjunctive Normal Form
15Theorem3-SAT is NP-complete
Proof 1) 3-SAT is in NP (by guessing the
assignment to variables and verifying that ?(x1,
x2 xn) 1) 2) f of Cook/Levins theorem can be
converted 3-SAT form
16Definition Vertex Cover
Given graph G (V,E), a subset V1 of vertices
is a vertex cover if each edge in E is adjacent
to at least one vertex in V1 Vertex-Cover
(G,k) G has a vertex cover of size
at most k
173-SAT ltp Vertex Cover
Input Boolean formula F (a or b or not c)
AND ((not a) or b or d) AND C clauses using N
variables
Output graph G G has a vertex cover of size
2C N if and only if F is satisfiable
18Output graph GC triangles and N pairs
a
a
b
d
b
c
19- Each instance vertex of a variable is connected
to one - of the variables pair vertices
- T if the instance is not negated
- and F if the instance is negated
20Showing the construction reduces 3-SAT to vertex
cover
1. If there is a satisfying assignment then
there must be a vertex cover of size 2C N 2.
If there a vertex cover of size 2C N then there
must be a satisfying assignment
(reduction does not necessarily preserve the size
of the witness set)
21Showing 1.
Given an assignment, circle T or F accordingly,
a
a
b
d
b
c
22Showing 1. ...
For each triangle / clause circle two vertices,
leaving one true literal
This covers the edges
a
a
b
d
b
c
23Showing 2.
(At least) one of each true/false pair of
vertices must be in the cover
24Showing 2. ...
(At least) two vertices in each triangle / clause
must be in the cover
a
b
c
25Showing 2. ...
If any one of the clauses is not satisfied, then
one of the highlighted edges is not covered
a
b
c
26Hamiltonian Path
Directed_HP (G,s,t) G is a directed graph
with a path that starts at vertex s, ends at
vertex t, and visits every vertex of G exactly
once
27Hamiltonian Path
Directed_HP (G,s,t) G is a directed graph
with a path that starts at vertex s, ends at
vertex t, and visits every vertex of G exactly
once
28Hamiltonian Pathexample
s
t
This does have a Hamiltonian Path
29TheoremDirected-HP is NP-complete
30Proof
1. Directed-HP is in NP Witness/Certificate is
the path (sequence of vertices visited)
31Proof continued
2. Directed-HP is NP-hard by reduction from
3-SAT We will demonstrate f formulae
Graphs x vertices x vertices ? is satisfiable
iff f(?) is in Directed-HP
32Reduction 3-SAT to Directed-HP
Suppose ? has N variables and C clauses
Variable x1 x2 . . xN
s
The Variable Gadgets
t
33Reduction 3-SAT to Directed-HP Continued
Variable x1 x2 . . xN
Clausej X1 OR X2 OR XN
s
The Clause Gadgets
34Claim ? is satisfiable iff G has a Hamiltonian
path from s to t
35Proof ( ) If f is satisfiable by x1 T,
x2 F, xN T then the following path
works
Variable x1 x2 . . xN
s
36Proof ( )
Any Hamiltonian path must be of the above form