# Final Exam

### Directions:

• Answer the problems on the exam pages.
• There are four problems on pages 2-8, for 125 total points. Scale was A = 110, C = 70.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.
• Numerical answers that are naturals less than 100 must be computed exactly for full credit. Other numbers may be given by arithmetic expressions, including exponents, falling exponents, and the "choose" notation.

```  Q1: 35 points
Q2: 25 points
Q3: 35 points
Q4: 30 points
Total: 125 points
```

• Question 1 (35): This problem involves the following four languages over the alphabet Σ = {a,b}:
• L0 is the set of strings that do not end in b (including λ).
• L1 is the set of strings that end in exactly one b.
• L2 is the set of strings that end in exactly two b's.
• L3 is the set of strings that end in three or more b's.

• (a,5) Give regular expressions denoting each of the languages L0, L1, L2, and L3.
• (b,10) Build a four-state DFA that decides the language L2. (Hint: Your DFA should have one state corresponding to each of the four given languages.)
• (c.5) Argue, without using the state minimization algorithm, that there is no three-state DFA that decides L2.
• (d,15) Label the states of your DFA q0, q1, q2, and q3 to correspond to the four languages. Then prove by induction on all strings u that with your DFA, δ*(s,u) = qi if and only if u ∈ Li. (Here "s" refers to whichever of the qi's you have designated as the start state.) (Hint: Your inductive step will have four cases, one for each i. In each of these you must show that if u is in Li, then both ua and ub are in the sets Lj indicated by your DFA.)

• Question 2 (25): Let Z be the language over alphabet {a,b,c} that consists of all strings wcw, where w is a string in (a+b)*. (That is, Z = {u: ∃w: u = wcw ∧ w ∈ (a+b)*}.)

• (a,5) Given a natural n, how many strings of length n are in the language Z? (There will be separate answers for even and odd n.)

• (b,5) Suppose we choose an n-letter string at random from the language (a+b+c)*, with every string equally likely. What is the probability that we choose a string in Z? (Again, answer separately for odd and even n.)

• (c,5) Is it possible for a two-way DFA to decide the language Z? Justify your answer, based on results from lecture and observations about Z.

• (d,10) Informally describe how a (deterministic, one-tape) Turing machine could decide the language Z. (I don't want a state table, just a high-level description that indicates how the state table would be built.)

• Question 3 (35): This question begins with a λ-NFA M. It has state set {p,q,r}, start state p, final state set {r}, and four transitions in Δ: (p,λ,q), (p,b,r), (q,a,q), and (q,λ,r).
• (a,5) Draw a diagram of this λ-NFA M. Give three examples of strings in L(M) and three examples of strings not in L(M).
• (b,10) Using the construction from lecture, create an ordinary NFA N, with the same state set, such that L(N) = L(M). Remember that N's final state set may or may not be the same as M's.
• (c,10) Using the Subset Construction, make a DFA D from your NFA N with L(D) = L(N). (If you could not do part (b), you may give any correct DFA for this languaage by any method for partial credit.)
• (d,10) Using the construction from lecture on your DFA D, make a regular expression R such that L(D) = L(R).

• Question 4 (30): This question involves the following four predicates on cards in a standard 52-card deck. Remember that such a deck has thirteen cards in each of the four suits.
• S(c) means that c is a spade.
• R(c) means that c is a red card (a diamond or heart).
• B(c) means that c is a black card (a club or spade).
• E(c,d) means that cards c and d have the same rank (for example, both sevens).

We are given the following assumptions:

• (I) Every card is either red or black, but not both.
• (II) Every spade is black.
• (III) Given any card, there is a spade that has the same rank as it.