HOMEWORK 4 SOLUTIONS, CPSC 421/501, FALL 2015 Copyright:

advertisement
HOMEWORK 4 SOLUTIONS, CPSC 421/501, FALL 2015
JOEL FRIEDMAN
Copyright: Copyright Joel Friedman 2015. Not to be copied, used, or revised
without explicit written permission from the copyright owner.
1 Let L1 , L2 ∈ P, and let M1 and M2 be Turing machines that decide L1 and L2 ,
respectively, in time O(nc1 ) and O(nc2 ), respectively (for constants c1 , c2 ).
Then an algorithm that runs M1 on input w and then M2 takes time O(nc1 +nc2 ),
and can be used to accept L1 ∪ L2 (the algorithm accepts w iff both M1 and M2
accepts w).
To decide L1 ◦ L2 , given input w with |w| = n, we consider the n + 1 ways to
write w as the concatenation of two strings w = w1 w2 , and run M1 on w1 and M2
on w2 . Since w1 , w2 are of length at most n, this algorithm takes time at most n + 1
times O(nc1 + nc2 ), which is polynomial in n.
To decide L∗1 , we use a dynamic programming type algorithm: on input w, for
each 1 ≤ i ≤ j ≤ n, we wish to determine if w[i..j], i.e., the string consisting of
characters i through j of w, lies in L∗ . We do this by checking this for j = i, then
j = i + 1, etc. Specifically,
(1) first we determining this for j = i meaning that we see if the single character
w[i..i] lies in L1 ; (we can do this in any order, for i = 1, . . . , n)
(2) second then we do this for j = i + 1, so that w[i..i + 1] ∈ L∗1 either if
w[i..i + 1] ∈ L1 or else both w[i..i] and w[i + 1..i + 1] lie in L1 ∗ from the
previous case (again, the order of i doesn’t matter);
(3) thereafter, for k = 2, . . . , n − 1, we check if w[i..i + k] ∈ L∗1 by seeing if
w[i..i + k] ∈ L1 , or if for some k 0 ∈ [1..k − 1] we have w[i..i + k 0 ] ∈ L∗1 and
w[i + k 0 + 1..i + k] ∈ L∗1 .
In particular, for each 1 ≤ i ≤ j ≤ n we will check its memembership in L1 using
M1 , so that for the n(n + 1)/2 possible i, j pairs we will take O(nc1 ) time, for a
total of O(nc1 +2 ) time just to make all the L1 membership queries; in addition, we
build a table via dynamic programming which for each i, j will require j − i − 1
queries to the database already collected, for a total of O(n3 ) time. It follows that
this will require O(nc ) time, where c = max(c1 + 2, 3), which is polynomial in n.
2 Since p ⇒ q equals ¬p ∨ q, we have
f = ¬(x1 ∧ . . . ∧ xn−1 ) ∨ xn = ¬x1 ∨ ¬x2 . . . ∨ ¬xn−1 ∨ xn .
Research supported in part by an NSERC grant.
1
2
JOEL FRIEDMAN
But we claim that y1 ∨ y2 ∨ y3 ∨ y4 is true iff for some z we have
h = (y1 ∨ y2 ∨ z) ∧ (¬z ∨ y3 ∨ y4 )
is true: indeed, if any yi is true then we can choose z to make the clause not
containing yi true, and conversely, if h is true, then if z is true then either y3 or y4
is true, and if z is false then either y1 or y2 . It follows that f is true iff
(¬x1 ∨ ¬x2 ∨ z1 ) ∧ (¬z1 ∨ ¬x3 ∨ z2 ) ∧ (¬z2 ∨ ¬x4 ∨ z3 ) ∧ . . . ∧ (¬zn−3 ∨ ¬xn−1 ∨ xn )
is satisfiable.
3 We must show that SIMPLE-NP is in NP, and that any language in NP can be
reduced (in polynomial time) to SIMPLE-NP.
SIMPLE-NP is in NP since on input u = hM, w, 1t i we have t ≤ |u| = n (since t is
written in unary). Since the δ function of the Turing machine has to be described,
the number of possibilities for each Turing machine transition is at most n. It
follows that each possible transition can be specified by at most log2 n bits; hence
the at most n transitions can be specified by at most n log2 n bits; finally once the
n log2 n bits are “guessed” non-deterministically, we can simulate M on input input
w is polynomial time per computation step (like we would with a universal Turing
machine). Hence SIMPLE-NP is in NP.
Now let L be in NP, and therefore decided by a non-deterministic Turning machine, M , in time at most c1 nc2 , with c1 , c2 integers. Then on input w, to see if
w ∈ L or not, we can affix a description of M to w and to a sequence of c1 nc2 1’s.
c2
The computation to transform w to hM, w, 1c1 n i is polynomial time. [Assuming
c2 ≥ 2, then the most time consuming part of the transformation is to print out
c1 nc2 1’s, which can be done by having a counter count to |w| in binary, making
this counter c2 as long, and adding log2 c1 bits; then this new counter will count
out at least c1 nc2 bits, and no more than than 2c2 +1 times this many bits, which is
c2
still order nc2 time in total.] So w ∈ L iff hM, w, 1c1 n i lies in SIMPLE-NP. Hence
L is polynomial time reducible to SIMPLE-NP.
To show that SAT is NP-complete, the diffficult part is to show that a nondeterministic Turing machine, M , running in polynomial times can be expressed
by the satisfiability of a Boolean formula; constructing this formula takes some
effort. For SIMPLE-NP, the reduction simply writes down the description of this
machine, M . So the fact that SIMPLE-NP is NP-complete requires very little work
and is not particulary surprising.
Department of Computer Science, University of British Columbia, Vancouver, BC
V6T 1Z4, CANADA, and Department of Mathematics, University of British Columbia,
Vancouver, BC V6T 1Z2, CANADA.
E-mail address: jf@cs.ubc.ca or jf@math.ubc.ca
URL: http://www.math.ubc.ca/~jf
Download