# Practice for First Midterm Exam

### Directions:

• Answer the problems on the exam pages.
• There are seven problems, for 120 total points. 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 problems are true/false, with five points for the correct boolean answer and up to five for a convincing justification (proof, counterexample, quotation of result from lecture, etc.)

```  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) If X is any CFL and Y is any regular language, X ∩ Y must be regular.

• Question 2 (10): (True/false with justification) If X and Y are each CFL's and neither X nor Y is regular, then X ∪ Y must be a CFL and X ∪ Y must not be regular.

• Question 3 (10): (True/false with justification) IF M is a DFA such that all states of M are final states, then L(M) must be equal to Σ*, the set of all strings.

• Question 4 (10): (True/false with justification) If M is an NFA such that all states of M are final states, then L(M) must be equal to Σ*, the set of all strings.

• Question 5 (30): Let the language E be the set of all strings w over the alphabet {a,b} such that the number of a's in w equals the number of b's in w.
• (a,15) Describe a context-free grammar G such that E = L(G).
• (b,15) Describe a pushdown automaton P such that E = L(P). You may or may not want to use a general construction on your answer to (a).

• Question 6 (20): Let X be the language {anbn: n ≥ 0} and let Y be the language {bndn: n ≥ 0}. Let Z be the language {anb2ncn: n ≥ 0}.
• (a,10) Is the concatenation product XY a CFL? Justify your answer.
• (b,10) Is Z a CFL? Justify your answer, by reference to (a) or otherwise.

• Question 7 (30): Let X be the language of the regular expression b ∪ Σ*a.
• (a,10) Draw an NFA whose language is X. Make sure your NFA cannot accept the string ab.
• (b,10) Draw a DFA whose language is X, using a general construction on your answer from (a) or otherwise.
• (c,10) Give a four-state DFA whose language is X, if your answer to (b) is not already a four-state DFA. Argue that any correct DFA for X must have at least four states, either by running the minimization algorithm or by finding four strings that are pairwise X-inequivalent. Note added 25 February: Actually the minimal DFA of this language has three states, not four.