Title: Homework 8 Due Wednesday, April 12
1Homework 7Due Wednesday, April 12
1. Show that 2-SAT ? P where 2-SAT ? ? is a
formula and is in conjunctive normal form
with 2 literals per clause and ? is in SAT
The algorithm on the ensuing page runs in
quadratic time and determines whether ? is in
2-SAT
2- Make sure that ? is in 2-SAT form
- Let N be the number of variables and C the
number of clauses - Construct directed graph G on 2N nodes labeled
with all 2N possible literals. - If clause (lit1 OR lit2) appears in f, let
edges (lit1? lit2) and (lit2 ? lit1) appear
in G - Find all strongly connected components in G
- If ? i 1ltiltN s.t. xi and xi are in the same
component, then ? is not satisfiable. Otherwise
? is satisfiable.
32. Prove that if P NP then ? i?0, Sip
Si1p Proof P NP ? S0p S1p. Note that for
any L?P1p, we have L ? S1p S0p and so L?P0p.
This implies P0p P1p Let i be any integer and
let L be any language ? S1p . If i is even,
then L x ? y1? y2 ? yi ? yi1 s.t. (x,
y1, y2 , ... yi , yi1) ? L and ? j, 1ltjlt i1,
we have yj O(xk) where L ? P and k is a
constant integer. L x ? y1 ? yi s.t. (x,
y1, y2 , ... yi) ? L and ? j, 1ltjlt i1, we have
yj O(xk) where L (a0, a1, ... ai)
?ai1 s.t. (a0, a1, ... ai, ai1)?L and ai1
O(a0k) ? NP P Therefore, if i is even,
then Sip ? Si1p ? Sip Si1p If i is odd, then
L x ? y1? y2 ? yi ? yi1 s.t. (x, y1, y2 ,
... yi , yi1) ? L and ? j, 1ltjlt i1, we have
yj O(xk) where L ? P and k is a constant
integer. L x ? y1 ? yi s.t. (x, y1, y2 ,
... yi) ? L and ? j, 1ltjlt i1, we have yj
O(xk) where L (a0, a1, ... ai) ?ai1
s.t. (a0, a1, ... ai, ai1)?L and ai1
O(a0k) ?P1p P Therefore, if i is odd, then
Sip ? Si1p ? Sip Si1p
43. True or False or Unknown (Prove your answer
if T or F) ? A,B, If B ? P and Altm B, then A ?
P This is false. It is known (by the Time
hierarchy theorem) that P S0 ,p ? S0, and
therefore that ? A s.t. A ? S0 but A ? P. Also,
the set B 1 ? P. We show that A ltm B. We
will show f f domain(A) ? strings, f is
computable ?x, x ? A ? f(x)? B On input x, Mf
decides whether x ? A and then outputs 1 if x ?
A and 0 if x ? A
5Problem 4. Sipser 7.26 Sipser describes a game
PUZZLE in which K cards are placed in a box in
one of two orientations flipped around a vertical
axis. There are R rows per card with a hole
either on the left side of the card, right side
of the card, both, or neither. PUZZLE is those
sets of cards that have an set of orientations
that completely covers the bottom of the
box. Show that PUZZLE is NP-complete. Proof --
Please refer to the slides of April 17 and 19
65 Show that co-NP P1,p where
co-NP L L ? NP P1,p L ? k, a
language L in P s.t. L x ? w,
w O(xk), s.t.
(w,x) ? L
7Proof
co-NP L L ? NP L L ? S1,p L ?
integer k and a language L ? P
s.t. L x ? w, where w O(xk),
we have (w,x) ? L L ?
integer k and a language L L ? P
s.t. L x ? w, where w O(xk), we have
(w,x) ? L P1,p
86. Prove or disprove ATM is NP-hard This is
true. We show 3-SAT ltp ATM We show a function f
s.t. 1) f formulas ? TMs x strings 2) f is
poly-time computable 3) ?f, f ? 3-SAT ? f(f)?
ATM Let Mf be a DTM that computes 3-SAT (in
exponential time perhaps). I.e. 3-SAT
L(Mf) On input f, Mf outputs (Mf, f) Note f is
poly-time computable because Mf is constant.
97. Prove that CC is NP-complete where CC
(G,k) undirected graph G has a clique-cover of
size k A clique-cover of a graph is a set of
cliques s.t. every vertex of the graph is a
member of at least one of the cliques. Note that
the size of the clique-cover is the number of
cliques. Use VERTEX-COVERpairs and eliminate
triangles first. Proof Step 1 CC (G,k) ?
S s.t. S is a clique-cover of undirected graph G
and S lt k ? S1,p NP To prove CC is NP-hard,
we show that VERTEX-COVERpairs ltp
VERTEX-COVERnotriangles ltp CC where
VERTEX-COVERnotriangles (H,q) H is an
undirected graph with no cliques of size 3 and H
has a vertex cover of size at most q Note that
to prove CC is NP-hard, we do not need to prove
that VERTEX-COVERnotriangles ? NP In class (and
in the notes), we showed VERTEX-COVERpairs ltp
VERTEX-COVERnotriangles Here, we show
VERTEX-COVERnotriangles ltp CC
10(step 2)
We must demo a function f s.t. 1) f undirected
graphs x integers ? undirected graphs x
integers 2) f is poly-time computable 3) ? (G,k),
(G,k) ? VERTEX-COVERnotriangles ? f(G,k) (H,q)
? CC
Suppose G (VG, EG). Let VG n, EG m
(step 3)
Define f. ? (G,k), f(G,k) (H,q) where H
an undirected graph of m vertices, one vertex for
every edge in G. ? e1,e2 ? VH EG, edge (e1,e2
) ? EH iff ? u?v?w ? VG e1 (u,v) and e2
(u,w). (note that because G is undirected, (u,v)
(v,u)) q k
11Showing the reduction f VERTEX-COVERnotriangles
to CC is correct
(step 4)
1. ? (G,k), (G,k) ? VERTEX-COVERnotriangles ?
f(G,k) (H,q) ? CC 2. ? (G,k), (G,k) ?
VERTEX-COVERnotriangles ? f(G,k) (H,q) ? CC
12Showing 1.
( )
(step 5)
Given (G,k) ? VERTEX-COVERnotriangles ? a
vertex cover C of G of size j lt k. We use vertex
cover C to define a clique cover in H of size j
as follows If C v1, v2, vj, let S s1,
s2, sj, where each set si is a set of vertices
in H corresponding to all edges in G that touch
vj. Claim S is a set of cliques in H Pf ? i,
any two vertices in si are edges in G that touch
the same vertex vi in G. So the vertices in si
will be adjacent to each other in H. Claim S
covers H Pf ? vertices e ?VH EG, edge e ? EG
VH will be adjacent to some vertex vi ? C and so
will be a member of clique si ? S
13Showing 2.
( )
(step 6)
Given (H,q) ? CC ? a clique cover of H of size j
lt k. We use clique cover H to define vertex
cover C of G of size j as follows If S s1,
s2, sj , let C v1, v2, vj, where each
vertex vi is the one vertex that is common to
each G-edge in set si Claim C is
well-defined Pf Because G has no triangles, any
set of edges in G that are adjacent to each other
must share a single common vertex. Claim C is a
vertex cover for G Pf ? vertices e ? EG VH, ?
si s.t. e ? si. So e is covered by vertex vi ? C.
148. Prove that Undirected_HP is NP-complete using
Direct_HP Undirected_HP (H,a,b) Undirected
graph H has a Hamiltonian path from a to
b Undirected_HP (H,a,b) ? p s.t. p is a
path from a to b in undirected graph H s.t. p
visits each vertex exactly once So Undirected_HP
? S1,p NP We show Undirected_HP is NP-hard
by showing Directed_HP ltp Undirected_HP We must
demo a function f s.t. 1) f directed graphs ?
weighted undirected graphs x integers 2) f is
poly-time computable 3) ? (G,s,t), (G,s,t) ?
Directed_HP ? f(G,s,t) (H,a,b) ? Undirected_HP
Let G (VG, EG). Let VG n
15(step 3)
? (G,s,t), f(G,s,t) (H,a,b) where H an
undirected graph of 3n vertices vin, vmiddle,
vout v ? VG ? v ? VG , the edges (vin, vmiddle)
and (vmiddle, vout) occur in H ? u,v s.t. (u ? v)
? EG edge (uout,vin) ? EH a sin b tout
16Showing the reduction f Directed_HP to
Undirected_HP is correct
(step 4)
1. ? (G,s,t), (G,s,t) ? Directed_HP ? f(G,s,t)
(H,a,b) ? Undirected_HP 2. ? (G,s,t), (G,s,t) ?
Directed_HP ? f(G,s,t) (H,a,b) ? Undirected_HP
17Showing 1.
( )
(step 5)
Given a Hamiltonian path p in G from s to t,
define Hamiltonian path p in H from a to
b Define p (vin, vmiddle) (vmiddle,vout) v
? VG ? (uout, vin)(u?v)? p Claim p is a
hamiltonian path from a to b Pf Because p has
no edges into s and no edges out of t, a vin
and b tout are the ends of p From the first
part of p s construction, we know each vmiddle
is visited exactly once. Because p is a
Hamiltonian path in G, we know that each vin and
are vout visited exactly once.
18Showing 2.
( )
(step 6)
Given a Hamiltonian path p in H connecting a and
b, define Hamiltonian path p in G from s to t
W.l.o.g. orient the path p from a to b p
a sin , , b tout Note that the witness
p must be of the following special form Claim
1 ? v ? G, vertices vin, vmiddle,vout must
occur in sequence and in that order in p. Pf
Because each middle vertex is connected only to
the corresponding in and out vertices, ? v ?
G, vertices vmiddle must be preceded either by
vin or vout and followed by whichever of those
two did not precede it. Now we use induction to
prove that the triples must appear in the
in-middle-out order. Base case The first
such triple in sequence will be sin, smiddle,sout
. Inductive step Each out vertex is only
connected to its middle vertices and other in
vertices. So the third vertex in the ith triple,
the out vertex, must be followed by the in
vertex of the next triple. Therefore, if the ith
triple is in the form, so must the i1st triple
be in that form.
19Let p v1in , v1middle, v1out, v2in , v2middle
, v2out , vNin , vNmiddle, vNout , Define p
v1,v2, ...vN Claim 2 p is a hamiltonian path
from s to t. Pf. Note a) Every vertex of G
occurs in p. b) The first vertex is s and the
last is t. c) ? i, 1ltiltN-1, there really is a
directed edge ( vi ? vi1 ) in G.
209. Define TSP (Traveling Salesperson Problem)
and prove that TSP is NP_complete using
Undirected_HP TSP (Q,k) Undirected complete
(fully-connected) graph Q with weights on its
edges has a Hamiltonian cycle of length at most
k TSP (Q,k) ? C s.t. C is a hamiltonian
cycle in Q and Se?EQ weight(e) lt k So TSP ?
S1,p NP We show TSP is NP-hard by showing
Undirected_HP ltp TSP We must demo a function f
s.t. 1) f undirected graphs x vertices x
vertices ? weighted undirected graphs x
integers 2) f is poly-time computable 3)
?(H,a,b), (H,a,b) ? Undirected_HP ? f(H,a,b)
(Q,k) ? TSP Let H (VH, EH). Let VH n
21(step 3)
? (H,a,b), f(H,a,b) (Q,k 2n-1) where Q
(VQ VH, EQ, WQ ) Note VH are copies of the
vertices of H EQ all possible pairs of vertices
of Q VQ weight(u,v)u?v?VQ ? u,v, if (u,v)
(s,t), then weight (s,t) 1 otherwise if
(u,v) ? EH then weight(u,v) 2 if (u,v) ? EH
then weight(u,v) 100 k 2n-1
22Showing the reduction f Undirected_HP to TSP is
correct
(step 4)
1. ?(H,a,b), (H,a,b) ? Undirected_HP ? f(H,a,b)
(Q,k) ? TSP 2. ?(H,a,b), (H,a,b) ?
Undirected_HP ? f(H,a,b) (Q,k) ? TSP
23Showing 1.
(step 5)
Given a Hamiltonian path p in H from a to b,
define hamiltonian tour C in Q of weight at most
k Define C p ? (a,b) Claim 1 C is a
hamiltonian tour in Q Pf p is a H.Path in H.
So C is a H.Tour in Q because Q has the same
vertices as H and (a,b) completes the cycle Claim
2 C has total weight k The weights in Q of the
edges taken from p are each 2. There are n-1 of
these. The weight of the edge (a,b) is 1. So
the total weight is 2n-1.
24Showing 2.
(step 6)
Given a hamiltonian tour C in Q of weight at most
k, define Hamiltonian path p in H from a to b
Note that the witness C must be of the following
special form Claim 1 C contains edge (a,b) and
the other edges of C must also be in H. Pf Note
that all edges except (a,b) have weight 2 or
greater and C has weight at most 2n-1 and C has
n edges. This implies that C must consist of 1
edge of weight 1 and n-1 edges of weight 2. The
only edge of weight 1 is (a,b) and all edges of
weight 2 are contained in H. Claim 2 C-(a,b)
is a Hamiltonian path in H from a to b Claim 1
implies that C is a Hamiltonian tour in
H?(a,b). Therefore, C-(a,b)is a Hamiltonian
path in H from a to b