# Solutions to Final Exam (Version A) Spring 2020

### Directions:

• Answer the problems on the exam pages.
• There are four problems, each with multiple parts, for 120 total points. Actual scale A = 105, C = 70.
• The textbook, course website, and notes are allowed. No other books, calculators, or collaboration.
• In case of a numerical answer, an arithmetic expression like "217 - 4" need not be reduced to a single integer.

Question text is in black, solutions in blue. Grading notes are in blue bold-face.

```  Q1: 30 points
Q2: 30 points
Q3: 30 points
Q4: 30 points
Total: 120 points
```

• Question 1 (30): One day, Duncan went to the park and met his friends Becky, Cindy, Maggie, and Pushkin, so that the set S of dogs at the park was {b, c, d, m, p}. Define three unary predicates on S, so that for any dog x, GT(x) means “x got a treat”, RO(x) means “x ran off”, and SN(x) means “x sat nicely”.

• (a, 10) Translate the following statements as indicated:

• Statement I (to symbols): Every dog who sat nicely got a treat.

∀x:SN(x) → GT(x)

Most got this right, except for a few ↔ or ∧ in place of the →.

• Statement II (to English): (RO(p) ↔ ∃z:(z≠p) ∧ RO(z)) ∧ ¬SN(p)

Pushkin ran off if and only if some other dog ran off, and Pushkin did not sit nicely.

I took off a point if I couldn’t tell that you had the last “¬SN(p)” outside of the ↔. The best way to write this was probably to move that phrase to the beginning, but a comma was also usually convincing.

• Statement III (to symbols): Neither Duncan nor Maggie sat nicely, and one of them ran off while the other got a treat.

¬(SN(d) ∨ S(m)) ∧ ((RO(d) ∧ GT(m)) ∨ (RO(m) ∧ GT(d)))

This was evidently the hardest translation. As we told several people on Piazza, this statement says what it says (that one dog ran off and the other got a treat) and doesn’t say what it doesn’t say (anything about a dog not running off or not getting a treat). The most common error here was to xor the two ands instead of or-ing them.

• Statement IV (to symbols): At least two different dogs sat nicely.

∃u:∃v: (u ≠ v) ∧ SN(u) ∧ SN(v)

Most people got this right — some missed saying that the two dogs were different.

• Statement V (to English): ∀y:((¬RO(y)) → GT(y))

Every dog who did not run off got a treat.

Most got this right.

• (b, 5) Consider the six propositions GT(d), GT(m), RO(d), RO(m), SN(d), and SN(m). There are 26 = 64 possible assignments of truth values to these propositions. How many of these are consistent with Statement III? Justify your answer. (Hint: If you make a truth table, you can simplify your life by considering only four of the six variables.)

There are seven. There are four where ¬SN(d), ¬SN(m), GT(d), and RO(m) are all true. There are four where ¬SN(d), ¬SN(m), GT(m), and RO(d) are all true. This double counts the one where ¬SN(d), ¬SN(m), GT(d), GT(m), RO(d), and RO(m) are all true, so the total is 4 + 4 - 1 = 7. We could also verify this by directly checking the 16 cases with ¬SN(d) and ¬SN(m) with a truth table.

I gave full credit for counting the cases correctly for an incorrect translation.

• (c, 15) Using Statements I-IV, prove Statement V. You may use English, symbols, or a combination, but make your use of quantifier proof rules clear.

Let x be an arbitrary dog. We must prove that either x ran off or x got a treat.

If x = d or x = m, we know from Statement III that at least one of GT(x) and RO(x) is true.

If x = p, Statement II tells us that RO(x) is true, since some dog other than p (either d or m) ran off.

If x = b or x = c, we know that SN(x) is true because there are at least two dogs who sat nicely, and they do not include d or m (by III) or p (by II). This leaves only b and c to be those two dogs. Then by specializing I to x, we derive GT(x).

These were mostly either correct or fairly confused. I gave substantial credit for figuring out which two dogs sat nicely.

• Question 2 (20+10): Let Σ = {a, b, c, d, e} and let S be the language (aa + bb + cc + ddd + eee)*.

• (a, 5) Prove that for all naturals n, except for n = 1, there exists a string of length n in S. (Hint: Show the n = 0 case separately and then use induction on all n with n ≥ 2.)

Let P(n) be the statement “S contains a string of length n”. P(0) is true because λ is in any star language. We use odd-even induction for all n with n ≥ 2. The base cases are P(2), which is true because of “aa”, and P(3), which is true because of “ddd”. If we assume P(n), so that some string w of length n is in S, then P(n+2) is true because the string waa is in S.

There were several valid ways to prove this, not all involving induction. For example, you could say “Let n be an arbitrary natural, with n ≠ 1. If n = 0, let the string be λ. If n ≥ 2 and n is even, let the string be (aa)n/2. If n ≥ 2 and n is odd, let the string be (ddd)(aa)(n-3)/2.”

• (b, 5) Let f(n) be the number of strings in S of length n. Explain why, for all n with n ≥ 3, f(n) = 3f(n-2) + 2f(n-3).

Let n ≥ 3 and consider any string w in S of length n. Since n > 0, w has a last letter. If this letter is a, b, or c, then w must be of the form uaa, ubb, or ucc for some string u in S of length n-2. If the last letter is d or e, then w must be of the form vddd or veee for some string v in S of length n-3. So for every string in S of length n-3, there are exactly two strings in S of length n, and for every string in S of length n-2, there are exactly three strings in S of length n. It follows that the number of strings in S of length n is exactly 3f(n-3) + 2f(n-2), as claimed.

Here it’s important that the argument actually talk about strings.

• (c, 10) Prove, for all naturals n, that f(n) = [2n+2 + (-1)n(3n+5)]/9. (Hint: Use strong induction on the recurrence from part (b), with base cases for n = 0, n = 1, and n = 2.

As suggested, we use strong induction on all natural n. For the base cases, f(0) = 1 because λ is in S (since S is a star language). This matches the formula, as [20+2 + (-1)0(3(0) + 5)]/9 = (4+5)/9 = 1. We have f(1) = 0 because there is no way to make a string of length 1 by concatenating strings of length 2 or 3. This matches the formula, because [21+2 + (-1)1(3(1) + 5)]/9 = (8-8)/9 = 0. Finally, f(2) = 3 because the only strings of length 2 in S are aa, bb, and cc. This matches the formula because [22+2 + (-1)2(3(2) + 5)]/9 = (16 + 11)/9 = 3.

For the inductive case, we assume that f(n-3) and f(n-2) match the formula, and compute f(0):

2[2n-1 + (-1)n-3(3(n-3) + 5)]/9 + 3[2n + (-1)n-2(3(n-2) + 5)]/9 = (1/9)[2n + 3(2n) + (-1)n(-6(n-3) -10 + 9(n-2) + 15)] = (1/9)[2n+2 + (-1)n(-6n + 18 - 10 + 9n -18 + 15)] = (1/9)[2n+2 + (-1)n(3n + 5)]

Some potentially tricky arithmetic here (and I took off points for leaving out too many steps). Note that it’s important to do all three base cases, and that those base case arguments need to involve both the given formula and a count of the strings of that size in S.

• (d, 10) The Myhill-Nerode Theorem tells us that Σ* is divided into a finite number of S-equivalence classes. How many are there? Justify your answer. You may quote the Myhill-Nerode Theorem to justify your answer if you do so correctly.

The MN Theorem tells us that the number of equivalence classes is equal to the number of states in the minimal DFA for the language. So let’s design a DFA for S. We have state 0 which is the start state and the only final state. We make a loop for each of the possible strings that should bring us back to 0, so we have δ(0, a) = 1, δ(1, a) = 0, δ(0, b) = 2, δ(2, b) = 0, δ(0, c) = 3, δ(3, c) = 0, δ(0, d) = 4, δ(4, d) = 5, δ(5, d) = 0, δ(0, e) = 6, δ(6, e) = 7, δ(7, e) = 0. All other values of δ are 8, including δ(8, x) for any letter x, so that 8 is a death state.

If we minimize this nine-state DFA, our first partition is F = {0} and N = {1,2,3,4,5,6,7,8}. The behaviors of the states in N are then FNNNN for 1, NFNNN, for 2, NNFNN for 3, NNNNN for 4, NNNFN for 5, NNNNN for 6, NNNNF for 7, and NNNNN for 8. We then make a new transition where the only non-singleton class is X = {4, 6, 8}. (We will name the other classes 0, 1, 2, 3, 5, and 7.) Now the behaviors of the states in X are XXX5X, XXXX7, and XXXXX. The third partition thus has only singleton classes. We have proved that this nine-state DFA is minimal, and thus that S has exactly nine equivalence classes.

Quoting the MN Theorem works if you have the minimal DFA for the language. I gave a lot of credit for having the correct DFA without a minimization proof. Some people left off the death state.

• Question 3 (30): Let N be a λ-NFA with state set {1, 2, 3, 4, 5}, start state 1, only final state 4, and transitions (1, λ, 2), (1, b, 3), (2, a, 4), (2, λ, 5), (3, b, 5), (4, a, 3), (4, b, 5), and (5, λ, 4). This is the λ-NFA used in the 2:00 exam. The 8:30 exam had the transition (4, λ, 5) instead of (4, b, 5).

• (a, 10) Construct an ordinary NFA N’ from N using the construction given in lecture. You should get six a-moves and eleven b-moves. (The NFA from the λ-NFA on the 8:30 exam had eight a-moves and three b-moves.)

We add three λ-moves (1, λ, 4), (1, λ, 5), and (2, λ, 4) to make the transitive closure.

(1, b, 3) makes itself only.

(2, a, 4) makes itself and (1, a, 4).

(3, b, 5) makes itself and (3, b, 4).

(4, a, 3) makes itself, (1, a, 3), (2, a, 3), and (5, a, 3).

(4, b, 5) makes itself, (1, b, 5), (2, b, 5), (5, b, 5), (1, b, 4), (2, b, 4), (4, b, 4), and (5, b, 4).

State 1 becomes final as it has a λ-path to 4.

• (b, 5) Construct a DFA D from N’ using the Subset Construction.

The constructed DFA has the following six states:

{1} (final) with a-move to {3, 4} and b-move to {3, 4, 5}

{3, 4} (final) with a-move to {3}, b-move to {4, 5}

{3, 4, 5} (final) with a-move to {3}, b-move to {4, 5}

{3} (non-final) with a-move to ∅, b-move to {4, 5}

{4, 5} (final) with a-move to {3}, b-move to {4, 5}

∅ with both moves to ∅

• (c, 5) Construct a minimal DFA D’ equivalent to D. If you do not use the minimization construction from the textbook and supplemental lecture, prove that your D’ is in fact minimal.

We begin with a partition of F = {1, 34, 345, 45} and N = {3, E}. The behaviors of the states in F are FF for 1, NF for 34, NF for 345, and NF for 45. The behaviors of the states in N are NF for 3 and NN for E. So 1, 3, and E must be in classes by themselves. If we let X be the class {34, 345, 45} we find that all three states have behavior 3X, so they can be merged into a single state X. The minimal DFA thus has four states 1, X, 3, and E. 1 has both moves to X, X has an a-move to 3 and a b-move to itself, 3 has an a-move to E and a b-move to X, and E has both moves to E. 1 is the start state and 1 and X are the final states.

• (d, 5) Construct a regular expression R with L(R) = L(D). You may start from either D or D’.

We take D’ and add an additional state f with λ-moves from 1 and X. (We don’t need a new start state since there are no moves into 1.) We first eliminate E, creating no new transitions. We then eliminate 2, creating the new transition (X, ab, X) which merges with the existing (X, b, X) to make (X, ab + b, X). Finally, eliminating X gives us the single transition (1, λ + (a+b)(ab+b)*, f) (after merging with (1, λ, f)) and from this we read off the regular expression “λ + (a+b)(ab+b)*”.

• (e, 5) Construct a λ-NFA with the same language as R, using the construction from lecture and the textbook.

The λ-NFA has state set {i, p, q, r, s, f}, with start state i and final state f. The transitions are (i, a, p), (i, b, p), (i, λ, f), (p, λ, q), (q, b, s), (q, λ, s), (q, a, r), (r, b, s), (s, λ, q), and (s, λ, f).

• Question 3 (30) (8:00 version): Let N be a λ-NFA with state set {1,2,3,4,5}, start state 1, only final state 4, and transitions (1, λ, 2), (1, b, 3), (2, a, 4), (2, λ, 5), (3, b, 5), (4, a, 3), (4, λ, 5), and (5, λ, 4).

• (a, 10) Construct an ordinary NFA N’ from N using the construction given in lecture. You should get eight a-moves and three b-moves.)

We add three λ-moves (1, λ, 4), (1, λ, 5), and (2, λ, 4) to make the transitive closure.

(1, b, 3) makes itself only.

(2, a, 4) makes itself, (1, a, 4), (1, a, 5), and (2, a, 5).

(3, b, 5) makes itself and (3, b, 4).

(4, a, 3) makes itself, (1, a, 3), (2, a, 3), and (5, a, 3).

State 1 becomes final as it has a λ-path to 4.

• (b, 5) Construct a DFA D from N’ using the Subset Construction.

The constructed DFA has the following five states:

Start state {1} (final) with a-move to {3, 4, 5} and b-move to {3}

{3, 4, 5} (final) with a-move to {3}, b-move to {4, 5}

{3} (non-final) with a-move to ∅, b-move to {4, 5}

{4, 5} (final) with a-move to {3}, b-move to ∅

∅ with both moves to ∅

• (c, 5) Construct a minimal DFA D’ equivalent to D. If you do not use the minimization construction from the textbook and supplemental lecture, prove that your D’ is in fact minimal.

We begin with a partition of F = {1, 345, 45} and N = {3, E}. The behaviors of the states in F are FN for 1, NF for 345, and FF for 45. These three states must thus all be separated. The behaviors of the states in N are NF for 3 and NN for E. So the DFA D is already minimal.

• (d, 5) Construct a regular expression R with L(R) = L(D). You may start from either D or D’.

We take D = D’ and add an additional state f with λ-moves from 1, 345, and 45. (We don’t need a new start state since there are no moves into 1.) We first eliminate E, creating no new transitions. We then eliminate 3, creating the new transitions (1, bb, 45), (45, ab, 45), and (345, ab, 45). The last of these merges with an existing transition to make (345, b + ab, 45). We then eliminate 345, creating (1, a, f) (which merges with an existing transition to make (1, λ + a, f)) and (1, a(b+ab), 45) (which merges with an existing transition to make (1, bb + a(b + ab), 45). Now eliminating 45 gives us a final regular expression of λ + a + (bb + a(b + ab)(ab)*.

• (e, 5) Construct a λ-NFA with the same language as R, using the construction from lecture and the textbook.

The λ-NFA has state set {i, m, n, o, p, q, r, s, f}, with start state i and final state f. The transitions are (i, a, m), (i, b, n), (n, b, p), (m, b, p), (m, a, o), (o, b, p), (i, λ, f), (i, a, f), (p, λ, q), (q, b, s), (q, λ, s), (q, a, r), (r, b, s), (s, λ, q), and (s, λ, f).

• Question 4 (30): The following are fifteen true/false questions, with no explanation needed or wanted, no partial credit for wrong answers, and no penalty for guessing.

• (a) There exists a language that is not Turing recognizable.

TRUE. We proved LBS to be such a language.

• (b) Every language that is not the language of any DFA has an infinite number of words.

TRUE. In homework we saw how to build a DFA for any finite language.

• (c) There exist languages L and M such that M, LM, and ML are all regular languages, but L is not regular.

TRUE. If M is empty, LM and ML are also empty, no matter what L is. Since the empty set is regular, we can choose L to be any non-regular language.

• (d) There exist languages X and Y such that Y is regular, X is not regular, and X is a subset of Y.

TRUE. X can be any non-regular language and Y can be Σ*, which is regular.

• (e) The regular expressions (1*0*)* and (0 + 1)* denote different languages.

FALSE. Each denotes the set of all possible strings over {0, 1}.

• (f) There exists a multitape Turing machine whose language is not the language of any single-tape Turing machine.

FALSE. We proved in lecture that a multitape TM can be simulated by an ordinary one.

• (g) The less-than relation, <, on a set of real numbers is a partial ordering since it is antisymmetric and reflexive.

FALSE. It is not reflexive and thus not a partial order.

• (h) The maximum number of edges in a bipartite graph on 14 vertices is 49.

TRUE. If we have k nodes in the set A and 14 - k in the set B, the maximum possible number of edges is k(14 - k), which is maximized at 49 when k = 7.

• (i) Let h1(s) and h2(s) be two non-negative potential heuristics for the same search problem. If either h1(s) or h2(s) is an admissible heuristic, then so is h3(s) = min(h1(s), h2(s)).

TRUE. We know h3 is non-negative since it is the minimum of two non-negative functions. And we know it is bounded above by the true distance because at least one of h1 or h2 is.

• (j) There exist an undirected graph G and a node v in G such that the DFS and BFS trees of G rooted at v contain different numbers of edges.

FALSE. The number of edges in each tree is the number of nodes in v’s connected component, minus 1.

• (k) There exists a natural x such that 5x is congruent to 3, modulo 10.

FALSE. For any natural x, 5x is congruent to either 0 or 5, modulo 10.

• (l) A basket contains a certain number of apples. If we take them out 6 at a time, 1 apple remains. If we take them out 5 at a time, 3 apples remain. Then the original number of apples must have been greater than 12.

TRUE. We are given that x is congruent to 1 modulo 6 and to 3 modulo 5. By the Chinese Remainder Theorem this determines the value of x modulo 30, and by inspection this value is 13. So x is of the form 30k + 13 for some natural k, and thus x > 12.

• (m) If the converse of a statement is false, then its contrapositive is also false.

FALSE. The converse is equivalent to the inverse, and the contrapositive to the original statement. These two statements could have any combination of truth values.

• (n) Let A and B be any two languages (sets of strings). It is possible that A* ⊆ B*, but that A is not a subset of B.

TRUE. Let A = {aa} and B = {a}.

• (o) If T is any rooted tree with n nodes and e edges, then it is possible that n = e+2.

FALSE. We must have n = e + 1.