# First Midterm Exam, Spring 2009

### Directions:

• Answer the problems on the exam pages.
• There are seven problems for 120 total points. Actual scale was A=96, C=66.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.
• The first four questions are true/false, with five points for the correct boolean answer and up to five for a correct justification of your answer -- a proof, counterexample, quotation from the book or from lecture, etc. -- note that there is no reason not to guess if you don't know.

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

Total: 120 points
```

• Question 1 (10): True or false with justification: If N is any NFA, then there exists an NFA N' with three or fewer states such that L(N) = L(N'). (Recall that NFA's are defined to read at most one letter per transition.)

• Question 2 (10): True or false with justification: The book defines PDA's so they can push at most one, pop at most one, and read at most one character per transition. Suppose that we redefine PDA's to allow them to push or pop at most two characters per transition, and still read at most one. Then if M is any PDA, there exists a PDA M' with at most three states such that L(M) = L(M').

• Question 3 (10): True or false with justification: Define a left-regular grammar to be a context-free grammar with the property that there is at most one non-terminal on the right-hand side of any rule, and that this non-terminal must be the first character of the right-hand side. Then a language has a left-regular grammar if and only if it is regular.

• Question 4 (10): True or false with justification: Let L be the language {aibjck: j = 2i + k}. Then L is not a context-free language.

• Question 5 (20): A binary string is defined to be an ASCII string if (1) its length is divisible by 8, and (2) when it is partitioned into substrings of eight bits each, every such substring has an even number of ones.

• (a,5) Prove (by any valid method) that the set of ASCII strings is a regular language.

• (b,15) Find the number of states in the minimal DFA for the language of ASCII strings. (Equivalently, find the number of equivalence classes for the Myhill-Nerode equivalence relation for this language.) Prove your answer, by giving the minimal DFA and showing it to be minimal, or otherwise.

• Question 6 (30): Let P be the PDA with state set {p,q,r,s,f}, start state p. final state set {f}, input alphabet {a,b}, stack alphabet {a,b}, and the following six transitions: (p, ε, ε; q, b), (q, a, ε;, q, a), (q, b, ε; r, b), (r, b, b; s, ε), (s, a, a; s, ε), and (s, ε, b; f, ε). (Recall that a transition (s, c, d; t, z), for example, goes from state s to state t while reading c, popping d, and pushing z.)

• (a,5) Describe the language L(P) in English.

• (b,5) Using any valid method, give a context-free grammar whose language is L(P).

• (d,5) Explain why P is already in the normal form used in the proof that any PDA has an equivalent context-free grammar.

• (e,5) Describe the set of non-terminals in the grammar constructed from P in that proof.

• (f,5) Of the non-terminals listed in part (e), only some can possibly generate a string of terminals in the constructed grammar. Which ones, and why?

• Question 7 (30): Let D be the DFA with state set {1, 2, 3, 4, 5}, start state 1, final state set {2, 3, 4}, and the following transition function δ: δ(1, a) = 1, δ(1, b) = 2, δ(2, a) = 3, δ(2, b) = 2, δ(3, a) = 4, δ(3, b) = 2, δ(4, a) = 5, δ(4, b) = 2, δ(5, a) = 5, and δ(5, b) = 2.

• (a, 5) Describe the language L(D) in English.

• (b, 10) Give a regular expression denoting the language L(D). If you do not use the standard construction, give some idea why you believe your construction to be correct.

• (c, 5) A death state of a DFA is defined to be a state s that (1) is reachable from the start state, (2) is non-final, and (3) has δ(s, a) = s for every input letter a. Could any valid DFA for L(D) have a death state? Why or why not?

• (d, 5) Prove that no minimal DFA for any language can have more than one death state.

• (e, 5) Give necessary and sufficient conditions for a regular language to have a valid DFA with a death state.