a Solutions to Final Exam for CMPSCI 250, Fall 2017

Solutions to Final Exam Fall 2017

Directions:

• Answer the problems on the exam pages.
• There are four problems, each with multiple parts, for 120 total points. Actual scale was A = 108, C = 72.
• Some useful definitions precede the questions below.
• No books, notes, calculators, or collaboration.
• In case of a numerical answer, an arithmetic expression like "217 - 4" need not be reduced to a single integer.

```  Q1: 30 points
Q2: 20+10 points
Q3: 40 points
Q4: 30 points
Total: 120 points
```

Question text is in black, solutions in blue.

Here are definitions of some terms, sets, predicates, and statements used on this exam.

Question 1 deals with the following scenario:

The web site WeRateDogsTM gives numerical ratings of animals based on photographs, and publishes these at `twitter.com/dog_rates`. They provided ratings for a set A of six animals, consisting exactly of Cardie (c), Duncan (d), Floyd (f), Mia (m), Pushkin (p), and Tib (t). We thus have a function r from A to N where r(x) is the rating of animal x.

We have a number of additional predicates defined on A:

• E(x) means "animal x is enormous".
• ML(x, y) means "animal x is much larger than animal y" and this is defined to mean "E(x) ∧ ¬E(y)".
• D(x) means "animal x is a dog".

Question 2 also refers to the following six statements, where the variables are of type "animal or type "natural". The predicate P(n) means "natural n is prime".

The statements are:

• Statement I: Floyd, who is enormous, received a rating of 7, and no enormous animal received a higher rating.
• Statement II: ∀x: ∃y: P(r(x)) ∧ ((r(x) > 10) ↔ D(x))
• Statement III: Tib received the same rating as some animal much larger than herself.
• Statement IV: ∀x: ∃y: (x ≠ y) ∧ (r(x) = r(y))
• Statement V: Pushkin received a rating that was less than some other animal's rating and greater than some other animal's rating.
• Statement VI: ¬∀x:∀y: (D(x) ∧ D(y)) → (r(x) = r(y))

N is the set of naturals (non-negative integers, {0, 1, 2,...}.

Again, we define the predicate P on N so that P(n) means "n is prime".

Question 2 uses a recursive function f from N to n defeind by the rules f(0) = 1, f(1) = 0, f(2) = 1, and for n ≥ 2, f(n+1) = 4f(n) - 5f(n-1) + 2f(n-2).

Question 3 uses the following λ-NFA N, which has state set {1, 2, 3}, start state 1, final state set {3}, and transition relation Δ = {(1, λ, 2), (1, b, 3), (2, a, 1), (2, λ, 3), (3, b, 2)}.

Here is a diagram of N, with "L" representing λ:

``````        L
>(1) -----> (2)
|  <-----  |^
|     a    ||
|          ||
|         L||b
|          ||
|   b      V|
------->((3))

``````

• Question 1 (30): This question deals with the scenario described above, and with the six statements about a set of animals A, consisting of exactly the six animals Cardie (c), Duncan (d), Floyd (f), Mia (m), Pushkin (p), and Tib (t). It uses the function r: A → N and the predicates E, ML, D, and P defined above.

• (a, 10) Translate each of these six statements as indicated.

• Statement I: (to symbols) Floyd, who is enormous, received a rating of 7, and no enormous animal received a higher rating.

E(f) ∧ (r(f) = 7) ∧ ¬∃x: (r(x) > 7) ∧ E(x)

• Statement II: (to English) ∀x: P(r(x)) ∧ ((r(x) > 10) ↔ D(x))

Every animal's rating was a prime number, and every animal was rated above 10 if and only if it was a dog.

• Statement III: (to symbols) Tib received the same rating as some animal much larger than herself.

∃x: ML(x, t) ∧ (r(x) = r(t))

• Statement IV: (to English) ∀x: ∃y: (x ≠ y) ∧ r(x) = r(y)

For every animal, there was some other animal that received the same rating as it.

• Statement V: (to symbols) Pushkin received a rating that was less than some other animal's rating and greater than some other animal's rating.

∃x:∃y: (r(x) > r(p)) ∧ (r(y) < r(p)). Many people included x ≠ p and y ≠ p, which are the consequence of the two words "other" in the English statement. The statement does not say x ≠ y, though this follows from the properties of naturals and the fact that r is a function.

• Statement VI: (to English) ¬∀x:∀y: (D(x) ∧ D(y)) → (r(x) = r(y))

It is not the case that any two animals that are both dogs have the same rating. Equivalently, there exist two dogs with different ratings. Lots of people got this wrong, which had grave consequences on parts (b) and (c). Remember that a ¬ operator applies to the next item on its right, which in this case is the entire remainder of the statement because it is all in the scope of the ∀ quantifier.

• (b, 10) Assuming that Statements I-VI are all true, determine exactly with of the six animals are dogs, and prove your answer.

• By I, r(x) > 10 is false, so by II we know that Floyd is not a dog.
• By III, r(t) = r(x), where x must be enormous to satisfy ML(x, t), so by I r(t) ≤ 7 and Tib is also not a dog. (Although it turns out that this animal x must be Floyd, we can't get this from III alone.)
• By VI, two dogs x and y exists with r(x) ≠ r(y).
• Specifying IV to each of x and y, we get that two more dogs w and z exists, with r(x) = r(w) and r(y) = r(z). None of these four dogs can be equal to any of the others, as the pairs with the same ratings are given to be distinct by IV.
• So there are at least four dogs. Since we have identified two non-dogs and there are only six total animals, Cardie, Duncan, Mia, and Pushkin must all be dogs.

• (c, 10) Assuming that Statements I-VI are all true, prove that some dog received a rating of 13 or more.

• By II, dog ratings are all prime numbers greater than 10.
• By VI, there are two different dog ratings r(x) and r(y). (We can be more specific based on the analysis in (b), but there is no need.)
• The smaller of r(x) and r(y) must be at least 11 since 11 is the smallest prime number greater than 10.
• The other rating is thus a prime number greater than 11, and this number must be at least 13, as desired.
• We are done, but applying V we can also determine that Pushkin and one of the other three dogs have the smaller rating and the other two have the larger one.

• Question 2 (20+10): This question uses the functions f defined above. The rules defining f are f(0) = 1, f(1) = 0, f(2) = 1, and for any n with n ≥ 2, f(n+1) = 4f(n) - 5f(n-1) + 2(f(n-2).

• (a, 10) Prove by strong induction on all naturals n that f(n) = 2n+1 - 3n - 1. Make sure that you have the correct base cases! for n = 0 and n = 1.

We let P(n) be the statement "f(n) = 2n+1 - 3n - 1". For our base cases, we must verify P(0), P(1), and P(2), because the inductive case of the definition only tells us about f(n) for n ≥ 3. We must check that each of the three given values satisfies the formula: f(0) = 1 = 21 - 3(0) - 1, f(1) = 0 = 21 - 3(1) - 1, and f(2) = 1 = 23 - 3(2) - 1.

For the strong induction, we assume that P(i) is true for all i with i ≤ n, where n ≥ 2. We then have to prove that f(n+1) = 2n+2 - 3(n+1) - 1 = 2n+2 - 3n - 4. To do this we apply the strong IH to f(n), f(n-1), and f(n-2), and plug these values into the equation defining f(n+1):

f(n+1) = 4(2n+1 - 3n - 1) - 5(2n - 3n + 2) + 2(2n-1 - 3n + 5) = 2n-1(16 - 10 + 2) - n(12 - 15 + 6) - 4 - 10 + 10 = 2n+2 - 3n - 4.

• (b, 10) Prove by strong induction on all naturals n (not by using the result of part (a)) than f(n) is odd if and only if n is even. Make sure that you have the correct base cases.

Now we let P(n) be "f(n) is odd if and only if n is even". For our base cases we must verify P(0), P(1), and P(2) because our inductive rule does not tell us about these cases. P(0) is true because f(0) is odd and 0 is even, P(1) is true because f(1) is even and 1 is odd. P(2) is true because f(2) is odd and 2 is even.

Now we can apply the strong IH and get that P(n), P(n-1), and P(n-2) are all true, which should help us verify P(n+1). We need two cases, one where n is odd and one where n is even. (Many of you apparently missed the fact that the "if and only if" statement meant that we were talking about both odd and even n.)

If n is odd, then n+1 and n-1 are both even, and the SIH tells us that f(n-1) is odd. The rule defines f(n+1) as 4f(n) - 5f(n-1) + 2f(n-2). The first and third of these terms are even whatever f(n) and f(n-2) are, and the second term is odd because it is the product of the odd numbers -5 and f(n-1). So f(n+1) is odd, as it should be.

If n is even, we still have f(n+1) defined as the sum of three terms. The first and third are still even, but now the second is even as well because n-1 is odd and therefore by the SIH f(n-1) is even. So f(n+1) is the sum of three even numbers, and is even as it should be.

• (c, 10XC) Let g(n) be any function of the form a2n + bn + c, where a, b, and c are any real numbers. Prove that g satisfies the rule g(n+1) = 4g(n) - 5g(n-1) + 2g(n-2) for any n with n ≥ 2.

Note that I did not ask you to prove this by induction, and no induction is necessary. Many of you got full credit for an "induction proof" that gave the argument below in the inductive case, never using any IH. Others of you got confused about what you were supposed to be proving.

Here we are assuming that g(n) = a2n + bn + c for some real numbers a, b, and c, and proving that the rule g(n+1) = 4g(n) - 5g(n-1) + 2g(n-2) is valid. (The restriction to n ≥ 2 is a red herring.) This is actually quite easy:

g(n+1) = a2n+1 + b(n+1) + c

RHS of rule = 4(a2n + bn + c) - 5(a2n-1 + b(n-1) + c) + 2(a2n-2 + b(n-2) + c) = 2n-2(16a -10a + 2a) + n(4b - 5b + 2b) + (5b - 4b) + c(4-5+2) = 2n+1 + b(n+1) + c.

• Question 3 (40): This question is the usual one about Kleene's Theorem constructions, using the λ-NFA N given above.

• (a, 5) Use the construction from lecture and the text to find a λ-NFA whose language is denoted by the regular expression (a+bb)(a+b)*.

The machine for a+bb has three states {1, 2, 3} and transitions (1, a, 3), (1, b, 2), and (2, b, 3). Correction made 5 May 2018.) The one for (a+b)* has four states {3, 4, 5, 6} with transitions (3, λ, 4), (4, λ, 5), (4, a, 5), (4, b, 5), (5, λ, 4), and (5, λ, 6). Merging these two machines by identifying the two states called "3" gives us a six-state answer, with start state 1 and final state set {6}.

The construction here gives exactly four λ-moves. Having more than one out of place generally got four points out of five, and correct machines that were further from the construction got three.

• (b, 10) Using the construction form the text on the λ-NFA N given above (not on your answer to part (a)), build an ordinary NFA N' such that L(N') = L(N).

We still have state set {1, 2, 3} with start state 1, and state 1 becomes final because λ ∈ L(N), making the final state set {1, 3}.

To make the λ-moves transitively closed we must add one from 1 to 3.

The letter move (1, b, 3) gives rise only to itself. The letter move (2, a, 1) gives rise to six a-moves because it allows for a-paths from either 1 or 2 to any of 1, 2, or 3. The letter move (3, b, 2) gives rise to six b-moves because it allows for b-paths from any of 1, 2, or 3 to either 2 or 3. The move (1, b, 3) is created twice, so we have twelve total moves in N': (1, a, 1), (1, a, 2), (1, b, 2), (1, a, 3), (1, b, 3), (2, a, 1), (2, a, 2), (2, b, 2), (2, a, 3), (2, b, 3), (3, b, 2), and (3, b, 3).

• (c, 10) Using the Subset Construction on N', find a DFA D such that L(D) = L(N) = L(N').

The start state {1} is final. It has an a-arrow to {1, 2, 3} and a b-arrow to {2, 3}, both of which are final states. State {1, 2, 3} has an a-arrow to itself and a b-arrow to {2, 3}. State {2, 3} has an a-arrow to {1, 2, 3} and a b-arrow to itself. We complete the DFA with only three states, all of which are final. (This wasn't my original intention, but it turned out to be a reasonable problem anyway.)

• (d, 5) Use the minimization construction to find a minimal DFA D' with L(D') = L(D).

We partition the three states into a single set F of three final states. (We don't consider the empty set of non-final states to be part of the partition, since every set in a partition must be non-empty.) Each state has an a-arrow to F and a b-arrow to F. Since all three states have the same behavior, we have reached the final partition. Our DFA D' has a single state for the class F, with a-arrow and b-arrow to itself. It is the start state and also the only final state.

• (e, 10) Find a regular expression for the complement of L(N). To do this, take either D or D' and make a new DFA by changing its final states to non-final states and vice versa. Then use the construction from lecture and the text text to obtain a regular expression from this new DFA. Do not simplify your expression -- I want the one from the construction.

Many of you observed that the complement of L(N) was the empty language, but for full credit I wanted you to carry out the construction. When we make a DFA for the complement of L(D') out of D', we get one state p which is non-final and has both arrows to itself. To continue, we must add a new start state i and a new final state f, with a λ-move from i to p. Since there are no final states in the DFA for the complement, we don't add any λ-moves to f. Now we have a three-state r.e.-NFA and we can eliminate state p, which creates no new moves becuause there are no moves out of p. This yields a two-state r.e.-NFA with no moves at all, and we can observe that its regular expression is ∅ because the absence of any transition is the same thing as a transitition labeled ∅.

• Question 4 (30): Identify each of the following fifteen statements as true or false. There are two points for each correct answer, with no explanation needed or wanted. Note that there is no penalty for guessing. Some of these statements refer to terms defined at the beginning of the exam. sheet.

• (a) Define the relation Z on the set A from the scenario, so that Z(x, y) is true if and only if r(x) = r(y). Then Z is an equivalence relation.

TRUE. It is reflexive, symmetric, and transitive because equality on naturals has these three properties/

• (b) The relation ML on the set A, defined above, is antisymmetric and transitive but not reflexive.

TRUE. It is antisymmetric because we cannot have two different animals each much larger than the other (both would have be both enormous and not enormous). It is transitive because it is impossible to have both ML(x, y) and ML(y, z) be true for any x, y, and z (y would to be both enormous and not enormous). It is not reflexive (in fact it is antirelexive) because ML(x, x) would force x to be both.

• (c) There are no prime numbers that are both greater than 115 and less than 125.

TRUE. We can eliminate all the even numbers in that range and check the odds. 117 and 123 are divisible by 3, 119 = 7(17) and 121 = 112.

• (d) Let C(w) be a unary predicate on strings over {a, b}. It is possible that C(λ) and ∀w: C(w) → (C(wa) ∧ C(wba) ∧ C(wbb)) are both true, but ∀w: C(w) is false.

TRUE. C(w) could be, for example, "w ≠ b", and would have all these properties.

• (e) Let G be any forest (that is, any undirected graph with no cycles) and let v be a node in G. If we conduct both a breadth-first search and a depth-first search of G, with v as the start node and no goal node, then it is possible that some edge will be a tree edge in one of the search trees and not in the other. (Assume that we do not restart the search at a new node when the open list becomes empty.)

FALSE. Node v is part of a graph-theoretic tree, its connected component of the forest. Both searches will include all the edges of this tree as tree edges, directed away from v, so the two trees will be identical.

• (f) Let H be any connected undirected graph with n nodes and let u and v be nodes of H. It is possible that there is a path from u to v in H with exactly n edges, but no path from u to v in H with fewer than n edges.

FALSE. Any path with n or move edges must include n+1 or more nodes and thus include the same node more than once. There must then be a shorter path obtained by deleting the edges between two visits to the same node. So the shortest path cannot have n or more edges. If any path exists, a shortest path must also exist.

• (g) Let B(w) be a unary predicate taking one argument that is a string over the alphabet {a, b}. If B(aa) and ∀u: B(u) → (B(abu) ∧ B(bau) ∧ B(wa) ∧ B(wb)) are both true, than B(w) is true for any string u in the regular language (ab+ba)*aa(a+b)*.

TRUE. A string in this regular langauge consists of zero or more strings from {ab, ba}, the string aa, and zero or more strings from {a, b}. Any such string can be made from aa by prepending copies of ab and ba, and appending copies of a and b. Each such move preserves the property b, so that property holds for the final string as well.

• (h) Every non-empty language has at least two Myhill-Nerode equivalence classes.

FALSE. The language (a+b)* from Question 3 is a counterexample (and in fact the only counterexample). It has a single equivalence class and its minimual DFA has only one state, but it is not the empty language.

• (i) Let AW be the set of strings w over the alphabet {a, b} with the following property: There is a prefix u of w such that (1) u contains exactly two more a's than b's, and (2) every proper prefix of u has a number of a's and a number of b's that differ by at most one. Then AW is defined by the regular expression (ab+ba)*aa(a+b)*.

TRUE. You can think of the sequence of strings as the points of a tennis match between players A and B, starting from deuce but possibly continuing after one player has one. Then AW is the set of strings in which Player A wins the match by getting a two-point lead before Player B does. Such a string consists of zero or more substrings of the form ab or ba (which return the game to a tie) followed by a string aa (causing Player A to win), followed by any string at all. This is exactly the set of strings defined by that regular expression.

• (j) Let M be a two-way DFA operating on a string of length n. If M takes more than n steps, it will never terminate.

FALSE. If k is the number of states in the 2WDFA, it cannot take more than kn steps without being in a loop. But it can easily take more than n. Consider with a start state 1, in which it moves right until it sees an a, then moves left and enters state 2. In state 2 it moves left until it sees a b, then moves right and enters state 3, in which it moves right to the end of the string. On the string bn-1a, it makes n-1 moves right, one move left, and then two moves right, taking n+2 moves total and then terminating. (Corrections in bold made 19 December 2018.)

• (k) Let M be a deterministic one-tape Turing machine, whose transition function δ satisfies δ(p, a) = (q, a, R) and δ(q, b) = (p, b, L). There there exists a configuration from which M will continue computing forever.

TRUE. From the configuration pab, the next step takes it to aqb, and the following step takes it back to pab. So it loops through these two configurations forever.

• (l) Let N be a nondeterministic Turing machine with two halting states h and h' (and possibly others). Let X be the set of strings w for which it is possible for N to start on input w and halt in h, and let X' be the set of strings w for which it is possible for N to start on input w and halt in h'. Then the language X ∪ X' is Turing recognizable.

TRUE. We make a Turing machine N' that simulates N until or unless it reaches a halting state. N' accepts if it reaches either h or h', and rejects if it reaches any other halting state. Then it is possible for N' to accept w if and only if it is possible for N to reach either h or h' on input w. Thus L(N') = X ∪ X'. We know that the language of any NDTM is Turing recognizable.

• (m) Let X, Y and Z be any three Turing recognizable languages. Let Q be the language (X ∩ Y) ∪ (X ∩ Z) ∪ (Y ∩ Z). Then it is possible that Q is not Turing recognizable.

FALSE. We can make a Turing machine M that runs recognizers for X, Y, and Z in parallel, until or unless two of the three recognizers have accepted. On an input w in Q, this will eventually happen because w is in at least two of the languages. But if w is not in Q, it is in at most one of the three languages and M cannot accept it. Therefore Q = L(M) and Q is Turing recognizable.

• (n) The set of descriptions of Turing machines that accept their own descriptions is not Turing recognizable.

FALSE. Using the universal Turing machine, we can make a machine Z that inputs a machine description for a machine M and then simulates M on its own description, accepting if and only if M accepts its own description. The given set is thus equal to L(Z) and must be Turing recognizable.

• (o) The set of descriptions of Turing machines that have non-empty languages is Turing recognizable.

TRUE. We can make a Turing machine Y that inputs a machine description for M and then, in parallel, simulates M on all possible strings, accepting if any of these computations accepts. If L(M) is non-empty, one computation will eventually accept and thus Y will accept M. If L(M) is empty, Y cannot accept M. So this set is equal to L(Y), making it Turing recognizable.