Question text is in black, solutions in blue.

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

**Question 1 (10):***(True/false with justification)*The language {(n,S,k): S is a set of binary strings each of length n, and there exists a boolean circuit C with k or fewer gates such that for any string w of length n, C(w) = 1 if and only if w ∈ S} is Turing decidable.TRUE. Given n, S, and k, there are only finitely many circuits with n inputs and at most k gates. With a deterministic Turing machine, we can try each one of these circuits and evaluate it on each of the 2

^{n}strings of length n, to verify that C(w) = 1 if and only if w ∈ S. We accept if this is true for some circuit and all the strings. We are guaranteed to halt.**Question 2 (10):***(True/false with justification)*If G is any context-free language with terminal alphabet {0,1}, there exists a family of boolean circuits {C_{n}: n ≥ 0} such that for any string w of any length n, w ∈ L(G) if and only if C_{n}(w) = 1.L(G) is in P by the CKY algorithm proved in lecture and in the book (Sipser Theorem 7.16). We also proved that any language in P has polynomial-size circuits (Sipser Theorem 9.30). This two results together imply that L(G) has polynomial-size circuits.

**Question 3 (10):***(True/false with justification)*Let EQ_{CFG}be the set of all pairs (G_{1}, G_{2}) of context-free grammars such that L(G_{1}) = L(G_{2}). Then EQ_{CFG}is Turing recognizable.FALSE. EQ

_{CFG}is not TD, as we proved by reduction to ALL_{CFG}(Sipser Exercise 5.1, on HW#4). But the complement of EQ_{CFG}is Turing recognizable because (G_{1}, G_{2}) is in the complement if and only if there is a string w that is in either L(G_{1}) or L(G_{2}), but not both. We can have a Turing machine that takes G_{1}, G_{2}, and looks for such a w, deterministically testing whether w is in one of these languages but not the other. The pair is in EQ_{CFG)}-bar if and only if some such w exists, so the language of this TM is EQ_{CFG}.**Question 4 (10):***(True/false with justification)*The language ab^{*}a, with alphabet {a,b}, has a four-state minimal DFA.TRUE. The DFA has four states: start state 1, state 2, state 3, and state 4, with 3 as the only final state. We have a-transitions from 1 to 2, 2 to 3, 3 to 4, and 4 to 4, and b-transitions from 1 to 4, 2 to 2, 3 to 4, and 4 to 4. It is clear that the language of this DFA is ab

^{*}a, so we have only to prove that this DFA is minimal.If we run the state minimization algorithm, we start with two sets N = {1,2,4} and F = {3}. We see that of the states in N, all go into N on input b, but 2 goes to F on input a while the other two go to F. So we have a second partition with two singleton sets F = {3} and Y = {2}, and the set X = {1,4}. Now 1 goes into Y on input a while 4 goes to X. We have shown that our partition must have all singleton sets, and the original DFA is minimal.

Similarly, we could instead show that no two states of this DFA can be merged by showing that they are not Myhill-Nerode equivalent. State 3 is the only final state and must be by itself. States 1 and 4 are separated by input aa, 2 and 4 by input a, and 1 and 2 also by input a.

**Question 5 (20):**Recall that a formula is in k-CNF if it consists of the AND of one or more clauses, where each clause is the AND of exactly k literals. (The literals in a clause need not be distinct -- the clause x_{2}∨ (¬x_{3}) ∨ x_{2}could legally occur in a 3-CNF formula.) The language k-SAT is defined to be the set of k-CNF formulas that are satisfiable.- (a,15) Prove that the language 7-SAT is NP-complete. (Don't forget to
show that 7-SAT is in NP.)
7-SAT is in NP because we can have a verifier that takes a formula and a string, and accepts if and only the formula is in 7-CNF and the string is a satisfying instance. This requires checking the format of the formula, checking the length of the string, and evaluating the formula on the string, and each of these three operations may be carried out in polynomial time. A formula is in 7-SAT if and only if some string exists making this poly-time verifier accept, so 7-SAT is in NP.

We complete the proof that 7-SAT is NP-complete by showing that 3-SAT ≤

_{p}7-SAT. (3-SAT is known to be NP-complete from the text and lecture.) Our reduction takes a 3-CNF formula φ and makes a 7-CNF formula ψ from it by taking the third literal of each clause of φ and repeating it to make a total of five identical literals, OR'd together to make a clause of ψ. Since each clause of ψ is equivalent to the clause of φ from which it was made, the overall formulas φ and ψ are equivalent and one is satisfiable if and only if the other one is. The poly-time reduction is thus valid, and it is clear that we can produce ψ from φ in polynomial (actually linear) time. - (b,15) Prove that if the language 1-SAT is NP-complete, then NP equals
co-NP. (Remember that co-NP is the set of all languages whose complements
are in P.)
It is easy to see that 1-SAT is in P. A 1-CNF formula is simply an AND of literals, and it is satisfiable if and only if it does not contain two literals that are negations of each other. We can easily check in quadratic time whether this is the case.

If 1-SAT were both in P and NP-complete, any language in NP would reduce to a P language and would thus be in P, i.e., P would equal NP. Then co-NP would be the set of all languages with complements in P, which is just P because a language is in P if and only if its complement is. Since NP and co-NP are both equal to P under this hypothesis, they are equal to each other.

- (a,15) Prove that the language 7-SAT is NP-complete. (Don't forget to
show that 7-SAT is in NP.)
**Question 6 (20):**A directed graph is said to be**strongly connected**if for any two vertices u and v, there is a directed path from u to v. The**out-degree**of a directed graph is the maximum number of directed edges coming out of any vertex. We define 1-STR-CONN to be the set of directed graphs of out-degree 1 that are strongly connected. Prove that 1-STR-CONN is in the class L = DSPACE(log n).Here is some Java-syntax pseudocode, with the vertices of the graph numbered from 0 through n-1:

`for (int u = 0; u < n; u++) for (int v = 0; v < n, v++) int marker = u; int count = 0; while ((count < n-1) && (marker != v)) { marker = endpoint of edge out of marker, if any, else marker; count ++;} if (marker != t) return false; return true;`

If the input graph is out-degree 1 (which is easy to check in logspace), there is at most one path out of any vertex u, and it either reaches v in the first n-1 steps or never reaches it at all. The code above rejects if there are any u and v with no directed path from u to v, and accepts if this never happens -- it is clear from the definition that it accepts if and only if the graph is strongly connected. The algorithm uses four variables which each range over n possible values, so the space used is O(log n).

In fact a graph is both strongly connected and of out-degree 1 if and only if it consists of a single directed cycle containing all n vertices. (If any vertex has out-degree zero, it cannot have paths to other vertices, and if it has in-degree other than one there are either vertices that cannot reach it or vertices it cannot reach. We can test whether the graph is a single n-cycle by seeing that each vertex has both in-degree 1 and out-degree 1, and that the path from vertex 0 reaches vertex 0 again after n edges and not before.

**Question 7 (40):**If N is any kind of nondeterministic machine taking an input string w, define the language Z(N) to be the set of all w such that N eventually accepts on**every**computation path with input w. (If there is any path of N on w that fails to halt, then w is not in Z(N).)- (a,10) Prove that if N is an NFA, then Z(N) is a regular language.
(Note that for an NFA, a "path on input w" must read the entire string w.)
The complement of Z(N) is the set of all w such that for some path of N on w, reading all of w, N rejects. Let N-bar be an NFA identical to N except for switching the final and non-final states. A string w is in Z(N)-bar if and only if it is in L(N-bar), since the path leading to a rejecting state of N is exactly an accepting path of N-bar. Z(N)-bar = L(N-bar) is regular as it is the language of an NFA, and thus Z(N) is regular by the closure of regular languages under complementation.

- (b,10) Prove that if N is a nondeterministic Turing machine, then Z(N)
is Turing recognizable.
Consider the tree of all possible computations of N on w. The string w is in Z(N) if and only if this tree is finite and has only accepting leaves. We can design a Turing machine that will attempt to construct this tree as long as the leaves it finds are accepting -- it rejects if it finds a rejecting leaf and accepts only if it completes the tree. Z(N) is the set of strings such that this Turing machine accepts, so it is a Turing recognizable language.

- (c,10) Give an example of a nondeterministic Turing machine N such that
Z(N) is not Turing decidable. Justify your answer.
Let N be the universal Turing machine, which takes a pair (M,w) as input and runs Turing machine M on string w, accepting if and only if M accepts. (This is a deterministic Turing machine, but any deterministic machine may be thought of as a nondeterministic machine that never makes any choices.) Z(N) and L(N) are the same language, because there is only one computation on any w and so all are accepting if and only if the one is accepting. But L(M) is just the language A

_{TM}, which we know not to be Turing decidable.

- (a,10) Prove that if N is an NFA, then Z(N) is a regular language.
(Note that for an NFA, a "path on input w" must read the entire string w.)

Last modified 16 May 2008