CSE596 Problem Set 7 Answer Key Fall 2015

advertisement
CSE596
Problem Set 7 Answer Key
Fall 2015
(1) Give a reduction f from the language DT M such that for all e, if e ∈ DT M then Mf (e)
runs in time n + 1, while if e ∈
/ DT M , then Mf (e) is not total. Deduce that for any particular
running-time function t(n) ≥ n + 1, the decision problem
Instance: A deterministic Turing machine M ;
Question: Does M run in time t(n)?
is undecidable—indeed, its language is not c.e. Then show that the language is co-c.e. (12+9
= 21 pts.)
Answer: Call the language of this problem Lt . Given e, define f (e) to be the code of a TM
M that acts as follows: On input w, M 0 (w) starts reading one character of w at each step.
Simultaneously on its worktapes, it writes down e—which is embedded in the code of M 0 —and
begins simulating Me (e). If this is all still going on when M 0 reaches the end of w, M 0 halts
and accepts w. But if the simulation finishes with Me accepting e, then M 0 goes into an infinite
loop. Analysis:
0
• e ∈ D =⇒ (∀w)M 0 (w) halts within |w| + 1 steps =⇒ M 0 runs in time n + 1 =⇒ M 0
runs within time t(n) (since t(n) ≥ n + 1) =⇒ f (e) ∈ Lt ;
• e ∈
/ D =⇒ Me accepts e =⇒ for all sufficiently long inputs sw, M 0 (w) sees the
acceptance before |w| steps and freaks out =⇒ for all but finitely many w, M 0 (w)
doesn’t halt =⇒ M 0 doesn’t run in any time t(n) =⇒ f (e) ∈
/ Lt .
This shows D ≤m Lt regardless of what the function t is, so Lt is not c.e.
However, Lt is co-c.e. Its complement ∼ Lt is defined for all e by:
e ∈ L̃t ⇐⇒ (∃w)[Me (w) does not halt within t(|w|) steps].
The statement inside the square brackets amounts to a decidable predicdate R(e, w), presuming
(as we may) that t(n) is a computable function. Thus for all e, e ∈ L̃t ⇐⇒ (∃w)R(e, w), so by
Theorem 3.3, L̃t is c.e. (Put more intuitively, failing to halt within t(|w|) steps on some input
w is a detectable event once you guess the bad w, so the corresponding language is c.e.) Thus
Lt is co-c.e.
Extra Remarks: All but five submissions made the body of M 0 say “Run Me (e) for t(n)
steps.” The relevant question to ask is, whose steps? You need extra steps to write e down and
to compute t(n) in the first place. So it won’t be M 0 running in t(n) steps, which is what the
target problem in the reduction demands.
That is, you need to make the t(n) time requirement apply to M 0 , not to M . One way to
do this—needing t(n) to be fully time constructible (this wasn’t stated but it’s reasonable to
assume it)—is to impose a t(n) time clock on the whole body of M 0 . Doing so would be fine,
but more work than needed.
I did have to deduct 3 points because the homework sheet clearly stated “if e ∈ DT M then
Mf (e) runs in time n + 1.” I wonder if the tendency to read “runs in time t(n)” as “runs in time
exactly t(n)” caused cognitive dissonance here. I did define this as halting within t(n) steps in
lecture, while the text does similar in its definition on page 77 using the words “at most t(n)
moves before halting.”
More likely this is another case of the pitfall of intension versus extension again. The
intension is “runs in t(n) steps” and the urge is to apply it as immediately as possible—which
is to Me rather than stepping back and reflect on the M 0 which is your target to build. General
advice: work backwards from the goals as well as forwards from the start of the directions, and
then the middle where the nub of the problem is will be easier to handle.
(2) A symmetric n × n 0-1 matrix A represents an n-vertex undirected graph GA = (V, E)
with Aij = 1 ⇐⇒ G has an edge between vertex i and vertex j. We’ll assume that GA has
no self-loops; i.e., Aii = 0 for all i. Represent A in row-major order as a binary string of length
N = n2 . Define L2 to be the language of A such that V can be broken into V1 ∪ V2 such that
all edges in GA go between V1 and V2 .
(a) Show that L2 belongs to P. You don’t have to design a Turing machine M to accept
L2 —you can write pseudocode using data structures (such as sets) and appeal to the
polynomial-time simulation of a RAM/assembly-program by a TM as covered earlier in
the course. As a function of the input length N (not n), what is the asymptotic running
time of your pseudocode? (This is how running time is measured in CSE531. 15+3 = 18
pts.)
(b) A useful theorem stays that if a graph is not in L2 , then it has an odd cycle—i.e., a path
of m edges that starts at some vertex v and comes back to v, such that m is odd. Sketch
how a nondeterministic TM can verify this condition using only O(log N ) space to track a
guessed path, thus showing that the complement of L2 is in NL. (Since NL is closed under
complement—a “shock” theorem whose proof at the end of chapter 5 will be beyond our
scope—this also shows that weirdly L2 is in NL as well. 12 pts.)
Answer: The one trick is to make sure every vertex is considered without assuming the
graph is connected. So maintain three sets: V1 , V2 initialized to ∅ and V0 initialized to V for
vertices needing colors. Then here is one possible answer:
while (V_0 is not empty) {
pick the least vertex v in V_0 by label;
V_1 += {v};
V_0 -= {v}’
Do breadth-first search from v, first adding its neighbors to V_2,
then neighbors of those neighbors to V_1 again, and so on until
no new neighbors are left. If at any time an added neighbor has an
edge to a neighbor in the same set (i.e., both in V-1 or both in V_2),
reject. All neighbors found get subtracted from V_0 as well.
}
accept. //V_0 = \emptyset so V = V_1 U V_2 and no monochrome edges.
This algorithm touches every entry A[i, j] for an edge-or-nonedge in the graph exactly once,
either to find a new neighbor or to check that the new neighbor doesn’t have any old neighbors
of the same color. Since the number of edges is bounded by N and N = Θ(n2 ), the running
time on a standard unit-cost RAM is O(N ) = O(n2 ). On a “fair-cost RAM” (also called a
log-cost RAM) there is an extra factor of log N = O(log n) since the vertex labels take log n
bits each. On a Turing machine the probes of entries A[i, j] might take O(N ) time each if you
have to lug the lone input tape head all the way to the other end of the tape to do the next
lookup. So that gives O(N 2 ) = O(n4 ) time. (Or can you organize the input to make it O(n3 )
time on a TM? Well, if we only need “polynomial in n” then we don’t have to care.)
(b) Guess a vertex v and write down v on two tapes, using basically log2 n space for each.
Initialize a counter to 0 on a third tape and write down n = |V | on a fourth tape. Guess a
neighbor u of v and replace v by u on the second tape while incrementing the counter. Do this
with a neighbor u0 of u and so on—at each step incrementing the counter and testing whether
u0 = v. Accept iff u0 = v at a time when the counter is odd. Stop and make this computation
return “no” if the counter hits n. The overall space is 4 log2 n = O(log n).
A fine point is that this process might accept on finding a path of odd length back to v that
isn’t a simple cycle but rather comes back to intermediate nodes u multiple times. But then
the path is a union of cycles, and since the overall length is odd, at least one of the cycles must
have odd length.
(3) Define L3 to be the language of undirected graphs G whose vertex set V can be broken
into V1 ∪ V2 ∪ V3 such that all edges from Vi go to Vj where j 6= i. For example, the 5vertex ”bowtie graph” G with E(G) = { (1, 2), (2, 3), (1, 3), (3, 4), (3, 5), (4, 5) } belongs to L3 ,
but the complete graph on 4 vertices does not. Show that L3 belongs to NP. (Think about
why your approach in the case of L2 fails, but don’t spend any time trying to patch it into a
polynomial-time algorithm here. 12 pts., for 63 on the set.)
Answer: Build an NTM N3 that on input G = (V, E) guesses a partition of V into disjoint
subsets V1 , V2 , V3 and then (deterministically) evaluates
n
^
(i, j) ∈ E =⇒ ∧3k=1 (i ∈
/ Vk ∨ j ∈
/ Vk ).
i,j=1
The guess succeeds and the machine accepts if this predicate comes out true. Evaluating it
takes O(N ) time (on a RAM) since it riffs through each edge and can look up i ∈ Vk ? in unit
time using bit-vectors for the three subsets (if you use a set data structure standard based on
balanced trees then it’s O(log N ) per lookup but we don’t care). So N3 runs in polynomial time
and accepts iff G ∈ L3 , so L3 is in NP. (In fact it is NP-complete, as we will investigate later.)
Download