# Solutions to Practice Final

#### 11 May 2008

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

• Question 1 (10): (True/false with justification) Every language in the class L (or DSPACE(log n)) is context-free.

FALSE. We know that the language {anbncn: n ≥ 0} is not context-free. But this language is in L -- to test whether a string w is in this format we first check that it is in a*b*c* and if it is, count the a's, b's, and c's to see whether the three numbers are the same. Counting up to n, the input length, takes only O(log n) space.

• Question 2 (10): (True/false with justification) The language PATH = {(G,s,t): G is a directed graph and G has a path from s to t} has polynomial-size circuits.

TRUE. We proved in class that any language in the class P has polynomial-size circuits. PATH is in P because we can carry out a breadth-first or depth-first search of G from s in polynomial time, and accept iff we find t in this search.

• Question 3 (10): (True/false with justification) If A and B are two languages where A ≤m B and B is NP-complete, then A is Turing decidable.

TRUE. B must be Turing decidable, and it cannot be ∅ or Σ* because these languages are not NP-complete even if P = NP. We proved that any language mapping-reducible to a TD language is itself TD.

• Question 4 (10): (True/false with justification) If X is a language that has polynomial-size circuits, i.e., for every n there is a circuit Cn that decides membership in X for inputs of size n, and size(Cn) = nO(1), then X must be decidable.

FALSE. There is no reason that a halting Turing machine must exist that can produce the circuits -- we are told only that they exist. In lecture we gave the example of the language {w: |w| = n and the binary description of n describes a TM that halts on blank input}. This language is clearly not TD, but for every input size there is a small circuit that either accepts all strings of that length or rejects them all.

• Question 5 (20): Let ELOGSPACE be the language {M: M is a Turing machine that uses O(log n) space on inputs of size n such that L(M) is not empty. Prove that ELOGSPACE is not Turing decidable.

We reduce ATM to the complement of ELOGSPACE. Let (M,w) be any input to ATM -- we create a logspace TM called N such that N accepts a string if and only if it describes an accepting computation of M on w. N must check that its input is a sequence of valid configurations of M, that the first of these configurations represents the start position of M on input w, that each configuration after the first follows from the one before it by the rules of M, and that the last configuration is accepting. This is a mapping reduction from ATM to the complement of ELOGSPACE because N has a non-empty language if and only if M accepts w.

It remains to show that we can build such an N that runs in space that is logarithmic in its input length. The time to test the first configuration depends only on M and w, not the length of the input -- it is O(1). To test that each configuration follows from the one before, we must compare each corresponding place in the two configurations to see that the rules of M have been followed. This requires a counter that records a number that is less than n, the input size of N, so it takes only O(log n) space. Finally checking for the accepting configuration takes only O(1) space.

• Question 6 (20): Recall that ECFG is the language {G: G is a context-free grammar and L(G) is not empty}. Prove that ECFG is Turing decidable. (Note: This is a result proved in Sipser.)

Let G be an arbitrary context-free grammar. We know that G can be converted into Chomsky normal form without changing its language. Given G in this form, we can determine which non-terminals of G, if any, can generate strings of terminals. This is true for any non-terminal A that has an "A --> a" rule, and recursively it is true for any A that has an "A --> BC" rule where B and C are already known to generate strings of terminals. We mark the terminal-generating non-terminals as we find them, and if we ever make a pass over the rules without finding a new terminal-generating non-terminal, we have found all of them. We then accept if and only if S generates a string of terminals.

Sipser gives a slightly different proof -- we know we can test any individual string for membership in L(G) with a halting Turing machine. From the proof of the CFL Pumping Lemma we know that if L(G) contains any strings at all, it must contain a string of length at most p, where p is a constant computable from the number of terminals and non-terminals in G. So we can test all strings up to this length, and report that L(G) is empty if and only if none of these strings is in L(G).

• Question 7 (40): We define an instance of the box problem to be a natural number n (with n ≥ 3), a finite alphabet Σ, an assignment of letters in Σ to all the border cells of an n by n box of cells, and a set of rules indicating exactly which 3 by 3 subboxes are allowed. (Thus a set of rules is a subset of the set Σ9 indicating the legal 3 by 3 boxes.) A box problem instance is called feasible if there exists an assignment of letters in Σ to all the n2 cells such that border cells are assigned as indicated and all the 3 by 3 subboxes are legal. The language BOX is {b: b is a feasible box problem instance}.

• (a,10) Prove that for any fixed n, the set of (strings denoting) feasible n by n boxes is a regular language.

For any fixed n, fixed finite Σ, and fixed set of rules, the number of feasible n by n boxes is finite because it is bounded by |Σ|n2. All finite languages are regular because we can make an NFA that has an accepting path for each string in the language.

• (b,10) Prove that given a set of rules and an assignment of letters to all the cells of an n by n box, we can check whether the assignment follows the rules using O(log n) space.

We need to check, for each pair of numbers (i,j) with 1 ≤ i ≤ n-2 and 1 ≤ j ≤ n-2, whether the 3 by three box centered at (i,j) follows the rules. The check takes O(1) time and space once we have read the contents of the 3 by 3 box onto a work tape. Making sure that we have tried all possible i and j requires two counters ranging up to n, or O(log n) space.

• (c,20) Either prove that BOX is in P or prove that BOX is NP-complete. (Extra credit for proving both.)

(Note that proving both would prove that P = NP, which is probably not true and almost certainly not proved by something you could come up with during an exam.)

In fact BOX is NP-complete. We can reduce an arbitrary NP language to BOX by a construction very similar to the Cook-Levin Theorem. Let M be a one-tape NDTM with time bound p(m) and thus space bound p(m) on inputs of length m. For any string w of length m in the proper alphabet, we want to create an input f(w) to the BOX problem such that w is in L(M) if and only if f(w) is in BOX.

The instance f(w) will have n = p(m), an alphabet that is the union of M's state set and tape alphabet, a border that puts a start configuration of M on the bottom and an accepting configuration at the top (we modify M to have a unique accepting configuration), and rules that make sure that the box can only be filled with the tableau of a valid computation of M. We know from the proof of Cook-Levin that it is sufficient to check all 2 by 3 subboxes, and our rules for 3 by 3 boxes can make sure that all 2 by 3 subboxes are valid.