551homework4sol

advertisement
CSCE 551: Theory of Computation
Homework 4 solution sketch
Spring 2010
04/21/10
1. (0.2 points) Exercise 7.1 b, e.
b. FALSE
e. TRUE
2. (0.2 points) Exercise 7.2 b, e.
b. TRUE
e. FALSE
3. (0.1 points) Exercise 7.5.
No.
4. (0.4 points) Exercise 7.9.
A polynomial time algorithm M for TRIANGLE works as follows.
M = “On input G, where G = (V, E) is an undirected graph:
1.
Enumerate all triples (u, v, w) with vertices u, v, w ∈ V and u < v < w.
2.
For each triple (u, v, w), check whether or not all three edges (u, v), (v, w)
and (u, w) exist in E. If at least one such triple is found, accept. Otherwise,
reject.”
We show that this algorithm runs in polynomial time. Enumeration of all triples requires
O(|V|3) time. Checking whether or not all three edges belong to E takes O(|E|) time. Thus,
the overall time is O(|V|3|E|), which is polynomial in the length of the input G.
Therefore, TRIANGLE ∈ P.
5. (0.4 points) Problem 7.12.
A polynomial time algorithm M for MODEXP works as follows.
M = “On input a, b, c, p, where a, b, c, p are binary integers:
1.
Calculate u = a mod p, initialize v to 1, and initialize i to 0.
2.
For b = bnbn-1…b1b0, do the following for n+1 times:
3.
If bi = 1 then v = vu mod p; u = u2 mod p; i = i+1
4.
If v  c (mod p), accept. Otherwise, reject.”
We show that this algorithm runs in polynomial time. Stages 1 and 4 are executed only
once. Stage 3 runs O(n) times, which is polynomial in terms of the length of b, and each
round of stage 3 can be implemented in constant time. Hence M is a polynomial time
algorithm for MODEXP.
6. (0.4 points) Problem 7.16.
Unary representation uses a sequence of 1s to represent a positive integer (e.g., 5 is
represented as '11111' in unary). The table shown in Fig. 7.57 is O(n2), so it is a
polynomial time reduction. However, if the numbers in the same proof method are
represented in unary, then the width of the table becomes roughly 10l+k, which is
exponential. That is why the proof fails to show that UNARY-SSUM is NP-complete.
To show that UNARY-SSUM is in P, you can try the dynamic programming method. Note
that the dynamic programming method would be exponential if the numbers are not
represented in unary, but is polynomial when the numbers are represented in unary.
7. (0.4 points) Problem 7.20.
a. A polynomial time algorithm M for SPATH works as follows.
M = “On input G, a, b, k, where G is an undirected graph with nodes a and b, and k is a
constant:
1.
Place a mark on node a.
2.
Repeat the following for k rounds:
3.
Mark every unmarked node v if there is an edge between v and a
node u that was marked in the last round.
4.
If b is marked, accept. Otherwise, reject.”
We show that this algorithm runs in polynomial time. Stages 1 and 4 are executed only
once. Stage 3 runs at most k times and each round of stage 3 can be implemented in
O(|E|). Hence M is a polynomial time algorithm for SPATH.
b. First, LPATH is in NP because the following is a polynomial time verifier for LPATH:
V = “On input G, a, b, k, c:
1.
Test whether c starts with a, ends with b, and the length is at least k.
2.
Test whether G contains all the nodes in c.
3.
If both pass, accept; otherwise, reject.”
Next, we show that UHAMPATH P LPATH. This is very straightforward. For an
instance of UHAMPATH G, s, t where G = (V, E) is an undirected graph, we construct
an instance of LPATH with the same G, s, t and set k to |V|-1. To show that this reduction
works, observe that if there is a Hamiltonian path from s to t in G, then there is a simple
path of length k from s to t. In the reverse direction, if there is a simple path of length k
from s to t, then there is a Hamiltonian path from s to t in G. This reduction works in O(1)
time.
8. (0.4 points) Problem 7.21.
First, DOUBLE-SAT is in NP because the following is a polynomial time verifier for
DOUBLE-SAT:
V = “On input , c:
1.
Test whether c contains two different assignments.
2.
Test whether both of the two assignments satisfy .
3.
If both pass, accept; otherwise, reject.”
Next, we show that 3SAT P DOUBLE-SAT. Given a formula , define f() =   ’,
where ’ is a formula with every literal in  complemented (e.g., x becomes x). To
show that this reduction works, observe that if  is satisfiable, then   ’ has at least two
satisfying assignments, one is the same as one satisfying assignment for , and another
one is by complementing each variable’s assignment in the previous satisfying
assignment. In the reverse direction, if   ’ has at least two satisfying assignments,
then either  or ’ is satisfied. If  is satisfied, then we are done. If ’ is satisfied, we can
just complement the assignment of every variable to get a satisfying assignment for .
The time taken by this reduction is polynomial to the number of variables in .
9. (0.4 points) Problem 7.23.
a. We give a polynomial time decider M for CNF2 as follows.
M = “On input   does the following:
1.
Consider the first clause of . If it is of the form x, and there is a clause x
in , reject.
2.
Otherwise the first clause is of the form x  A. Scan through  and if x or
x occurs in more than 2 places, reject.
3.
If x does not appear negated in other clauses, remove every clause where x
occurs. If there remain no clauses in , accept,
4.
If there are two clauses x  A and x  B in , remove them from  and
add A  B to , and go to stage 1.”
It is clear that M is a decider of CNF2. Observe that every time M processes one variable,
either the result is reached (accept or reject) or the number of clauses in  is decreased by
1 or 2. Hence the running time of M is polynomial in terms of the number of variables.
b. First, CNF3 is in NP because the following is a polynomial time verifier for CNF3:
V = “On input , c:
1.
Test whether each variable in  occurs in at most 3 places.
2.
Test whether c is a satisfying assignment of .
3.
If both pass, accept; otherwise, reject.”
We show that 3SAT P CNF3. We define a polynomial time reduction f from 3SAT P
CNF3 as follows. When given an input instance  of 3SAT, f( ) constructs an instance of
CNF3 according to the following procedure:
1.
Pick the first propositional variable (reading from left to right) in  that
occurs more than 3 times in the formula, suppose it is p, and suppose it
occurs at n places: (x1  A1), …, (xn  An), where the xi are p or p. If no
variable occurs more than 3 times, output .
2.
Choose fresh variables p1, …, pn, remove all the conjuncts (xi  Ai) from
the formula and add as a conjunct the formula
(p1  A1)  (p1  p2)  (p2  A2)  (p2  p3) . . . (pn  An)  (pn  p1).
3.
Go to stage 1.
Clearly, f( ) is a formula in which every variable occurs at most three times. It is also
clear that  satisfiable iff f( ) is satisfiable. f is polynomial in terms of the number of
variable in .
Download