# First Midterm Exam

### Directions:

• Answer the problems on the exam pages.
• There are five problems on pages 2-6, for 120 total. Probable scale is somewhere around A=105, C=70.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.
• The first four questions are each statements which you are to determine to be true or false. You get five points for a correct boolean answer (so there is no reason not to guess if you are not sure) and up to five for a convincing justification (proof, counterexample, quotation from the text or from lecture, etc.)

```  Q1: 10 points
Q2: 10 points
Q3: 10 points
Q4: 10 points
Q5: 30 points
Q6: 50 points
Total: 120 points
```

• Question 1 (10): (True/False with justification) Let M be a PDA with the property that it never, when reading any string, can put more than three total characters on its stack. Then L(M) is a regular language.

• Question 2 (10): (True/False with justification) Let X by a CFL whose complement X-bar is also a CFL. Then X must be a regular language.

• Question 3 (10): (True/False with justification) Let N be an NFA with k states that has no ε-moves and never has more than one move from any state with the same letter label. (That is, N can be obtained from some DFA solely by deleting moves.) Then there exists a DFA for L(N) with exactly k+1 states.

• Question 4 (10): (True/False with justification) Let Σ = {0,1} and let f be the function from Σ* to Σ* that erases all 0's, so that for example f(01001) = 11. Let Y be any regular language over Σ. Let Z be the set of all strings that can be made by applying f to some string in Y -- formally, Z = {z: ∃y: (y ∈ Y) ∧ f(y) = z}. Then Z must be a regular language.

• Question 5 (30): Let N be the NFA with state set {1,2,3}, alphabet {a,b,c}, start state 1, final state set {2}, and the following transitions: (1,b,2), (1,b,3), (2,a,1), (2,a,3), (3,c,1), and (3,c,2). (In Sipser's notation, δ(1,b) = {2,3}, δ(2,a) = {1,3}, δ(3,c) = {1,2}, and all other values of δ are ∅. The diagram has six arrows: b-moves from 1 to 2 and 1 to 3, etc.)

• (a,15) Give a regular expression for the language L(N).

• (b,15) By the subset construction or otherwise, find a DFA D such that L(D) = L(N). Then either run the state-minimization algorithm on D, or otherwise find a DFA for L(N) with the smallest possible number of states. (If you do not use the state-minimization algorithm, you must explain why your final DFA is minimal.)

• Question 6 (50): These questions all deal with the grammar G that has non-terminal set {S}, terminal set (alphabet) {a,b,c,d}, start symbol S, and rules S → SS, S → aSb, S → cSd, and S → ε.

• (a,10) List all the four-letter strings in L(G) -- there are exactly eight of them. Then give derivations for at least two of these strings showing that they are in L(G).

• (b,10) State the Pumping Lemma for context-free languages. If p is the constant in the Pumping Lemma for the language L(G), show that the string apbpcpdd satisfies the conclusion of the Lemma. (Note: This problem makes no reference to any language not being a CFL. Of course L(G) is a CFL, because it is the language of a context-free grammar, G.)

• (c,15) Prove that L(G) is not a regular language. You may either use the Pumping Lemma for regular languages, or the method based on the Myhill-Nerode Theorem (finding an infinite set of pairwise L(G)-distinguishable strings). Please do not use the closure properties of regular languages -- I would like to see you use one of these two methods.

• (d,15) Describe a PDA whose language is L(G), by constructing the top-down or bottom-up parser or otherwise. Your description may be informal, as long as it is clear what your PDA may or may not do in any circumstance. If you use a standard construction from G, you need not prove that your PDA's language is L(G).