# Solutions to Final Exam, Spring 2015

### Directions:

• Answer the problems on the exam pages.
• There are eight problems for 120 total points plus 10 extra credit. Actual scale was A = 105, C = 60.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.
• Many useful definitions are given in a body before the questions.
• The first five questions are statements -- in each case say whether the statement is true or false and give a convincing justification of your answer -- a proof, counterexample, quotation from the book or from lecture, etc. You get five points for the correct boolean answer (so there is no reason not to guess if you don't know) and up to five for the justification.

```  Q1: 10 points
Q2: 10 points
Q3: 10 points
Q4: 10 points
Q5: 10 points
Q6: 30 points
Q7: 40+10 points
Total: 120+10 points
```

Exam text is in black, solutions in blue

If C is any class of computers, such as DFA's, CFG's, LBA's, TM's, strange variant TM's, etc.:

• AC = {(M, w): M is a computer in C and w ∈ L(M)}
• EC = {(M): M is a computer in C and L(M) = ∅}
• ALLC = {(M): M is a computer in C and L(M) = Σ*}

A language A is Turing decidable if A = L(M) for some Turing machine M that always halts.

A function f is Turing computable if there exists a Turing machine M such that for any string w, M when started on w halts with f(w) on its tape.

Recall that if A and B are two languages, A is mapping reducible to B, written A ≤m B, if there exists a function f: Σ* → Σ* such that for any string w, w ∈ A ↔ f(w) ∈ B. If such an f exists that is computable in polynomial time, we say that A is poly-time reducible to B, written A ≤p B. If f is computable in log space, we say that A is log-space reducible to B, written A ≤L B.

The following languages were proved to be NP-complete in the text or in Exercises, and you may assume without proof that each of them is NP-complete:

• 3-SAT = {φ: φ is a satisfiable formula in 3-CNF}

• 3-COLOR = {G: G is an undirected graph and the vertices of G may each be assigned one of three colors so that no edge connects two vertices of the same color}

• DHAMPATH = {(G, s, t): G is a directed graph in which there is a directed path from vertex s to another vertex t such that the path visits each vertex of G exactly once}

• UHAMPATH = {(S, s, t): G is an undirected graph in which there is an undirected path from vertex s to another vertex t such that the path visits each vertex of G exactly once}

• SUBSET-SUM = {(a1, a2,..., ak, t): the ai's and t are binary positive integers and there is a subset of the ai's that adds to exactly t}

• CLIQUE = {(G, k): G is an undirected graph and G has a set S of k vertices such that every two distinct vertices in S have an edge between them}

• VERTEX-COVER = {(G, k): G is an undirected graph and G has a set S of k vertices such that every edge in G has at least one endpoint in S}

King Arthur has n knights, including Sir Galahad and Sir Lancelot, and at any given time some of them may be quarreling with others. The relation Q(a, b) is defined to mean "knight a is quarreling with knight b", and this relation is assumed to be symmetric (that is, Q(a, b) → Q(b, a)). King Arthur himself is not quarreling with any knights.

Arthur of course has a Round Table at which he wishes to seat all the knights, without having two quarreling knights seated next to one another. Sometimes he sits at the table himself, with Sir Lancelot at his right and Sir Galahad on his left, but other times only the n knights are seated. (There is no empty seat in the latter case -- assume that the number of seats is always exactly what is needed.)

The language SEAT-CHECK is the set of pairs (Q, S) where Q is a list of which knights are quarreling with which, S is a seating arrangement for the table, and S does not have two quarreling knights seated next to one another.

The language SEAT-WITH-ARTHUR is the set of quarreling lists Q such that Q permits some arrangement of the n knights and Arthur at the table, with Galahad and Lancelot on either side of Arthur, and no quarreling knights seated next to one another. The language SEAT-WITHOUT-ARTHUR is the similar language where only the n knights must be seated.

Arthur also periodically sends all the knights out on quests, and he does not want to send two quarreling knights on the same quest. The language TWO-QUEST is the set of quarreling lists Q such that Q allows for a division of all the knights into two sets, neither of which contains a quarreling pair. The problem (not language) MIN-QUEST is to input a quarreling list Q and determine the minimum number of quests on which all the knights could be sent without a quarreling pair being sent on the same quest. (For example, if no knights are quarreling at all, the output of MIN-QUEST is 1.)

A Limited Alphabet Turing Machine is a two-tape deterministic Turing machine with a read-only input tape and a single read-write work tape. The input tape contains the input string w ∈ Σ*, with a special symbol \$ on each end that is not part of Σ. The work tape alphabet Γ contains a blank symbol but need not include any letters of the input alphabet Σ. The leftmost cell of the work tape contains a special symbol \$ that is not part of Γ and may not be overwritten.

In an LATM(k), the alphabet Γ has exactly k symbols, including the blank symbol but not including the special symbol \$. The transition function δ of the machine is this a function from Q × (Σ∪{\$}) × (Γ∪{\$}) to Q × Σ × Γ × {L, R}2.

• Question 1 (10): True or false with justification: Every DFA whose language is ab*a ∪ ba*b has six or more states.

FALSE. There is a correct DFA with five states {1, 2, 3, 4, 5}, where 1 is the start state, δ(1, a) = 2, δ(1, b) = 3, δ(2, a) = 4, δ(2, b) = 2, δ(3, a) = 3, δ(3, b) = 4, 4 is the only final state, δ(4, a) = δ(4, b) = 5, and 5 is a death state.

• Question 2 (10): True or false with justification: Let G be a grammar in Chomsky Normal Form, with k non-terminals, such that L(G) ≠ ∅. Then the shortest string in L(G) has fewer than 2k+3 letters.

TRUE. Following the proof of the CFL Pumping Lemma, we observe that if any string w of length n is in L(G), it has a parse tree of depth at least log2 n. (The tree has degree 2 since the grammar is in Chomsky Normal Form.) If log n > k+1, this tree must have two copies of the same non-terminal on a single path, and we can create a new parse tree for a shorter string by collapsing these two non-terminals into one. Thus any string longer than 2k+1 cannot be the shortest string in the language. Since there is at least one string, there must be a shortest string, and it can be no longer than this.

• Question 3 (10): True or false with justification: Assume for this question only that P ≠ NP. Let G1 and G2 be any two context-free grammars with the same alphabet. Then the language (L(G1) ∩ L(G2))* may be NP-complete.

FALSE. Every context-free language is in the class P, and the languages in P are closed under both intersection and star. So this language is in P, and if P ≠ NP there are no NP-complete languages in P.

• Question 4 (10): True or false with justification: It is not the case that ALLCFGp ECFG.

TRUE. We know that ALLCFG is an undecidable language, and that ECFG is decidable. If there were a poly-time reduction from ALLCFG to ECFG, this reduction would also be a mapping reduction. We would then have a violation of the downward closure of the class of decidable languages under ≤m.

• Question 5 (10): True or false with justification: Recall that CVP = {(C, w): C is a boolean circuit with n inputs, w ∈ {0, 1}n, and C(w) = 1}. If R is any regular expression, then L(R) ≤L CVP.

TRUE. We know that CVP is complete for the class P under ≤L reductions, and thus that any language in P reduces to CVP under such reductions. If R is any regular expression, L(R) is in P because the DFA equivalent to can be simulated in time polynomial in the length of the input string.

• Question 6 (30): These questions use the definition of Limited Alphabet Turing Machines (LATM's) given above.

• (a, 10) Describe an LATM(1) whose language is not context-free. You may use English or pseudocode as long as the operation of your machine is clear.

We can build an LATM(1) whose language is {anbncn: n ≥ 0}, a language that we know not to be context-free. The machine first scans the input and rejects if it is not in the language a*b*c*. It then returns both heads to the left endmarkers of their tapes. Now it moves right on the input tape to the first b, moving right on the worktape at the same time so that the distances moved on the two tapes is the same. Then it moves left on the input tape to the first c, moving left on the worktape at the same time so that if the number of a's and b's is the same, it reaches the \$ on the work tape at the same time it reaches the first c on the input tape. It rejects if this does not happen. Finally, it similarly checks whether the number of b's and the number of c's in the input string is the same, rejecting if it is not and accepting if it is. This behavior depends on the worktape contents only in that the machine checks for the \$ there.

• (b, 10) Prove that if X is the language of an LATM(1), then X is in the class P.

There are several possible proofs here. Perhaps the simplest is to note that the configuration of an LATM(1) can be defined by the state and two natural numbers, the head positions on the two tapes. The input head position is limited by n, the input size, and we can argue that if the LATM(1) has run more than O(n) steps, it has repeated a state and input head position. If it is in the same work tape position both times, it is in an infinite loop. If between those two times it moved right on the work tape, it will repeat that loop forever. If between those two times it moved left, it will eventually reach the \$ on the work tape. If it reaches the \$ on the work tape more than O(n) times, it must again be in a loop.

So no terminating computation can last more than O(n2) time, and a simulation of the machine for that long can be carried out in polynomial time.

• (c, 10) Prove that the language ALATM(2) is not Turing decidable.

We can convert an arbitrary one-tape TM M into an equivalent LATM(2) M', so that the function that takes (M, w) to (M', w) is a mapping reduction from the undecidable language ATM to ALATM(2). The existence of this reduction proves that ALATM(2) is not TD.

To make M', we choose an encoding of letters of the tape alphabet of M as binary strings of some fixed length. M' will translate its input tape into a binary version on its work tape, then simulate M on its work tape. For each step of M, it must read the string representing the currrent letter of M's work tape, deetermine what to do based on that string, the input letter it sees, and M's state, and then rewrite the string to represent the new letter on M's tape and move to the left or right an appropriate distance. A much larger but still finite state table for M' can do this.

• Question 7 (40+10): These questions all involve the problems and languages given above concerning King Arthur and his knights.

• (a, 10): Prove that the language TWO-QUEST is in the class NL.

As many of you noticed, TWO-QUEST is a thinly disguised version of the language BIPARTITE, shown to be in NL on the homework. If we define an undirected graph with a node for each knight and an edge between the nodes for any two knights who are quarrelling, then the knights may be sent on two quests if and only if this graph is bipartite.

The homework solution used the fact that the graph is bipartite if and only if there is not an odd-length path from any vertex to itself. Thus the set of non-bipartite graphs is in NL because a log-space TM could guess such a path and verify that its length is odd by counting the edges as it proceeds -- this is possible if and only if such a path exists. But by the Immerman-Szelepcsenyi Theorem, putting the language in co-NL suffices to put it in NL.

• (b, 10): Prove that if the MIN-QUEST problem can be solved in polynomial time, then P = NP.

We could use a solution to MIN-QUEST to solve the NP-complete problem 3-COLOR. Given an undirected graph G, we create a quarrelling list with two knights quarreling if and only if their nodes have an edge in G. Then we use the solution to determine the minimum number of quests needed to have no two quarrelling knights on the same quest. If this number is at most 3, then G can be three-colored -- if not, it cannot.

• (c, 10): Prove that the language SEAT-CHECK is in the class L.

To tell whether a pair (Q, S) is in SEAT-CHECK, we need to loop through each position i at the table, rejecting if the knight seated at i is quarrelling with the knight seated at i+1. If Arthur is not at the table, we also have to check whether the knight in position n is quarrelling with the knight at position 1 (if we have no position 0). To do this, the only memory we need is to store i and the numbers of two knights, which are three numbers of O(log n) bits each. This can clearly be done by a logspace TM.

• (d, 10): Prove that the language SEAT-WITH-ARTHUR is NP-complete.

Clearly this language is in NP because the seating arrangement is the certificate and we just showed that we can check a seating arrangement in L, and therefore in P.

We show it to be NP-complete by giving a poly-time reduction from the NP-complete language UHAM-PATH to SEAT-WITH-ARTHUR. Given an undirected graph G with vertices s and t, we make a quarrelling list where two knights are quarrelling if and only if their nodes do not have an edge between them. We map node s to Lancelot and node t to Galahad, or vice versa. Then a Hamilton path from s to t exists if and only if the knights can be seated with no quarrelling pair next to one another.

• (e, 10XC): Prove that the language SEAT-WITHOUT-ARTHUR is NP-complete.

Again this language is in NP because the seating arrangement is the certificate and we just showed that we can check a seating arrangement in L, and therefore in P.

To show this language NP-complete, we can give a poly-time reduction from SEAT-WITH-ARTHUR (which we just proved to be NP-complete) to SEAT-WITHOUT-ARTHUR. Given a quarrelling list Q for n knights, including Galahad and Lancelot, create a new list Q' by adding a new knight Mordred, who is quarrelling with every knight except Galahad and Lancelot. There is a seating arrangment for Q with Arthur if and only if there is a seating arrangement for Q' without Arthur, because Mordred can only be seated between Galahad and Lancelot, exactly where Arthur would sit in the first arrangement.