CSCE 551 Final Exam, April 28, 2016 Answer Key 1. (15 points) Fix any alphabet Σ containing the symbol a. For any language L Σ, define the language a\l := {w Σ wa L}. Show that if L is regular, then a\l is also regular. Answer: Assume L is regular. Given a DFA D = (Q, Σ, δ, q 0, F ) recognizing L, we define a DFA D as follows: D := (Q, Σ, δ, q 0, F ), where F := {q Q δ(q, a) F }. (Thus D differs from D only in the set of accepting states.) For any w Σ, we have w a\l wa L ˆδ(q 0, wa) F δ(ˆδ(q 0, w), a) F ˆδ(q 0, w) F D accepts w. Thus L(D ) = a\l, and so a\l is regular. 2. (10 points) Fix any language Σ containing 0. Let E be an enumerator (with output alphabet Σ) satisfying two properties when run: For infinitely many integers n 0, E prints 0 n at some point. E never prints a string with fewer 0 s than a previously printed string. (That is, for any strings x, y Σ, if E prints x first and y after, then y has at least as many 0 s as x (it could be the same number or more, but no fewer).) Show that the language enumerated by E is decidable. Answer: Here is a decision procedure M for L(E): M := On input w Σ : (a) Let n be the number of 0 s occurring in w. (b) Run E until either i. E prints w or ii. E prints 0 m for some m > n, whichever comes first. (c) If E prints w first, then accept; else reject. To see that M decides L(E), first suppose that w L(E). Then E eventually prints w. E cannot print any string with more 0 s than w before it prints w, so it cannot print 0 m for any m > n beforehand. Thus M will accept w. If w / L(E), then E never prints w, but it will eventually print 0 m for some m > n, so in this case M (halts and) rejects w. 1
3. (10 points) Let A be any Turing recognizable language such that, for all x Σ there exists y Σ such that x, y A (but there could be more than one such y). Show that there is a computable function f : Σ Σ such that x, f(x) A for all x Σ. [Hint: Use time slicing, a.k.a. dovetailing.] Answer: Here is a proof using an enumerator. Since A is Turing recognizable, there is some enumerator E enumerating A. Consider the following algorithm: M := On input x Σ : (a) Run E. (b) The first time E prints a string of the form x, y for some y Σ, then halt and output y. For each input x, we know that E must eventually print some string of the form x, y. Thus M always halts, and so it computes a function f : Σ Σ. By construction, x, f(x) A, because M only outputs a y such that x, y is printed by E (and thus is in A). (M just outputs the first such y it finds by running E). 4. (15 points) Let L := { M M is a TM that accepts exactly 2016 many strings}. Show that L is undecidable. Argue directly, without appealing to Rice s theorem. Answer: Suppose that L is decidable. Then here is a decision procedure for A TM : D := On input M, w, where M is a TM and w a string: (a) Construct the following TM R, fixing some symbol a in its input alphabet: R := On input x: i. Run M on input w. ii. If M ever accepts, then A. If x = a i for some integer i such that 0 i < 2016, then accept; B. Else, reject. iii. (If M does not accept w, then loop.) (b) If R L then accept; else reject. D is clearly a decider (it uses implicitly an assumed decision procedure for L). For any M and w: If M, w A TM, then M accepts w, and thus R accepts exactly 2016 many strings (namely, ɛ, a, aa, aaa,..., a 2015 ). It follows that R L, and so D accepts M, w. If M, w / A TM, then R loops on all its inputs, not accepting any string. That puts R / L, and hence D rejects M, w. 2
This shows that D is a decision procedure for A TM. Contradiction. Therefore L is undecidable. 5. (15 points) Let FIN NFA := { N N is an NFA and L(N) is finite}. Show that FIN NFA P by giving a polynomial-time decision procedure for FIN NFA. Give a high-level algorithm. Answer: The key idea is that an n-state NFA accepts infinitely many strings if and only if it accepts some string of length n (which is then pumpable to longer accepted strings). So here is a polynomial-time decision procedure for FIN NFA, and it uses something similar to the subset construction: D := On input N, where N is an NFA: (a) Let N = (Q, Σ, δ, q 0, F ), and set n := Q, the number of states of N. (b) Set S 0 := ɛ-closure({q 0 }). (c) For i := 1 to n compute S i := ɛ-closure q S i 1 a Σ {ɛ} δ(q, a) // S i is the set of states reachable by reading any input string of length i. (d) If S n contains an accepting state, or there is some accepting state reachable from a state in S n, then reject; else accept. D runs in polynomial time (particularly, Step (d) can be done via running breadth-first search from each state in S n ). And D accepts N if and only if N does not accept any strings of length n, or equivalently, L(N) is finite. 6. (10 points) Recall that for any positive integer k, we define k-colorability to be the language of all strings G such that G is an undirected graph and there exists a way to color the vertices of G with no more than k colors so that no two adjacent vertices are colored the same. It is clear (and you may assume) that k-colorability is in NP for every k, and we also know that 3-COLORABILITY is NP-hard. For any fixed k 4, show that k-colorability is NP-hard by finding a polynomial reduction from 3-COLORA- BILITY to k-colorability. Answer: Fix some k 4. Here is how we can p-reduce 3-COLORABILITY to k-colorability: Given a graph G, we output in p-time a graph G such that G is k-colorable if and only if G is 3-colorable: 3
(a) Let y 1, y 2,..., y k 3 be k 3 nodes not in G. (b) Add y 1, y 2,..., y k 3 to the vertex set of G. (c) Draw edges connecting each y i to all the vertices of G and to all the other y j for j i. (d) Let G be the resulting graph. Output G. The following proof of correctness is purely optional. Getting the reduction right counts for full credit. This construction can clearly be done in polynomial time. If G has a 3-coloring, then it can be extended to a k-coloring of G by assigning to each y i a unique color not used in G. Conversely, any k-coloring of G must assign distinct colors to y 1,..., y k 3, since they are all pairwise adjacent. Since all the y i are adjacent to all the vertices in G, none of the k 3 colors used for y 1,..., y k 3 can be used inside G. There are only 3 colors left, and so G is 3-colorable. 7. (15 points total) Let ϕ be the quantified Boolean formula ( x 1 )( x 2 )( x 3 )[ (x 1 x 2 x 3 ) (x 2 x 3 ) (x 1 x 3 ) (x 1 x 2 x 3 ) ]. (a) (10 points) Give the instance G, s of GG that ϕ maps to via the polynomial reduction of TQBF to GG described either in the book or in class. Draw the digraph G and label the start vertex s. Note that ϕ having an odd number of quantifiers may only require a slight modification of the construction. (b) (5 points) Is ϕ true? Explain. Answer: (a) Numbering the clauses C 1, C 2, C 3, C 4 from left to right, here is the instance of GG: 4
s C 1 x 1 x 1 C 2 x 2 x 2 C 3 C 4 x 3 x 3 The bottom two nodes represent consecutive dummy moves and may be bypassed completely. (b) ϕ is false. If x 1 = 1, then the formula reduces to (x 2 x 3 ) (x 2 x 3 ) (x 2 x 3 ), whence setting setting x 2 := 0 yields a contradiction. If x 1 = 0, then the formula reduces to (x 2 x 3 ) x 3, which again yields a contradiction when x 2 := 1. 8. (10 points) Prove that if TQBF P, then P = PSPACE. (We already know that P PSPACE unconditionally, so it suffices to show that PSPACE P.) [Note: There is nothing special about TQBF here, except that it is PSPACE-complete; any other PSPACE-complete language would work just as well.] Answer: Suppose TQBF P, and let A be any language in PSPACE. It suffices to show that A P. Since TQBF is PSPACE-hard, we have A p TQBF. It was proved in class and in the book that P is closed under p, which means that, since TQBF P by assumption, we have A P as well. 5