# Final Exam

### Directions:

• Answer the problems on the exam pages.
• There are five problems, each with multiple parts, for 120 total points plus 10 extra credit. Actual scale A = 110, C = 75.
• 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: 10 points
Q2: 20 points
Q3: 20+10 points
Q4: 30 points
Q5: 40 points
Total: 120+10 points
```

Question 3 deals with a set D of dogs, consisting of exactly the five dogs Arly (a), Cardie (c), Duncan (d), Knight (k), and Nico (n), and a set of four activities A, consisting of "barking" (bar), "chasing" (cha), "swimming" (swi), and "wrestling" (wre). The predicate L(x, y, z) means "dog x likes activity y with dog z". If y is any activity, the binary relation Ly on D is defined by Ly(x, z) ↔ L(x, y, z).

Question 3 also refers to the following six statements, where the variables are of type "dog" or type "activity":

• Statement I: For every activity y, the relation Ly is both reflexive and symmetric.

• Statement II: Cardie likes to wrestle with Duncan, but she does not like to wrestle with any other dog (except herself) and she does not like any other activity with Duncan.

• Statement III: Cardie likes both swimming and chasing with both Nico and Knight.

• Statement IV: ∀y: ∀z: L(a, y, z) ↔ ((y = bar) ∨ (z = a))

• Statement V: ∃y: ∀z: L(c, y, z)

• Statement VI: ∀z: ∃y: L(c, y, z)

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

Question 4 uses a recursive function from N to N defined by the rules f(0) = 0 and f(n+1) = 2f(n) + n.

Questions 4 and 5 use the following DFA D, which has state set {p, q, r}, start state p, final state set {p, q}, and transition function δ given by δ(p, a) = p, δ(p, b) = q, δ(q, a) = r, δ(q, b) = q, and δ(r, a) = δ(r, b) = r.

We also use D to define three functions p(n), q(n), and r(n) from N to N as follows. For any natural n, p(n) is the number of strings w of length n such that D (started in state p) finishes reading w in state p. (That is, such that δ*(p, w) = p.) Similarly, q(n) is the number of strings w of length n such that D (again started in state p) finishes reading w in state q, and r(n) is the number finishing in state r.

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

``````The DFA D:

___          ___         ___
|   | a      |   | b     |   | a, b
|   V        |   V       |   V
>((p)) -----> ((q)) -----> (r)
b             a

The lambda-NFA N ("L" = lambda):

___        ___
|   | a    |   | b
|   V      |   V
>(1) -----> (2) -----> (3) -----> ((4))
L           L         L

``````

• Question 1 (10): Compare and contrast the two concepts in each of the following pairs, giving enough detail to make it clear that you are familiar with them (2 points each):

• (a, 2) A back edge and a forward edge in the depth-first search tree of a directed graph.

• (b, 2) The prefix string and the postfix string for an arithmetic expression.

• (c, 2) The complement of a language and the one's complement of a binary string.

• (d, 2) The empty string and the empty language.

• (e, 2) A Turing decidable language and a Turing recognizable language.

• Question 2 (20): The following are ten true/false questions, with no explanation needed or wanted, no partial credit for wrong answers, and no penalty for guessing. Each one counts two points.

• (a) If Statement V above is true, then Statement VI must be true as well. (Ignore the other statements.)

• (b) If we want to store the relation L above as a boolean array, without assuming any of the statements, we will need exactly 100 boolean variables.

• (c) There is some natural number x such that for any natural number y, the congruence 14xy ≡ y (mod 25) is true.

• (d) The operation of concatenation on binary strings is associative but not commutative, and has an identity element.

• (e) If there is a path from node s to node t in a directed graph G, then a depth-first search of G with start node s and goal node t will always find a path from s to t with a minimum number of edges.

• (f) In any weighted graph with non-negative edge weights, the function h that has h(x) = 0 for every node x is always an admissible and consistent heuristic for an A* search.

• (g) Let G be a finite two-player deterministic game of perfect information, where the game ends with a real number payoff from Black to White. Assume that Black has a strategy that will ensure that he pays at most 3. Then White must have a strategy that guarantees her a payoff of at least 3.

• (h) If a language X is not regular, then there exists a Turing machine M such that X = L(M).

• (i) Suppose that a single-tape Turing machine M has the transition δ(p, ☐) = (p, a, R) where ☐ is the blank symbol. Then if M reaches the configuration ☐ab☐p☐, it is guaranteed never to halt.

• (j) If the union of two languages X and Y is Turing decidable, then both X and Y must themselves be Turing decidable.

• Question 3 (20+10): This question deals with five statements about a set of dogs D, consisting of exactly the five dogs Arly (a), Cardie (c), Duncan (d), Knight (k), and Nico (n), and a set of four activities A, consisting of "barking" (bar), "chasing" (cha), "swimming" (swi), and "wrestling" (wre). The predicate L(x, y, z) means "dog x likes activity y with dog z". If y is any activity, then the binary relation Ly is defined by Ly (x, z) ↔ L(x, y, z).

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

• Statement I (to symbols): For every activity y, the relation Ly is both reflexive and symmetric.

• Statement II (to symbols): Cardie likes to wrestle with Duncan, but she does not like to wrestle with any other dog (except herself) and she does not like any other activities with Duncan.

• Statement III (to symbols): Cardie likes both swimming and chasing with both Nico and Knight.

• Statement IV (to English): ∀y: ∀z: L(a, y, z) ↔ ((y = bar) ∨ (z = a))

• Statement V (to English) ∃y: ∀z: L(c, y, z)

• Statement VI (to English) ∀z: ∃ y: L(c, y, z)

Assuming that Statements I-IV are all true, it turns out that one of Statements V or VI must be true and the other must be false. You must determine which is which.

• (b, 10) Prove either Statement V or Statement VI from Statements I-IV. You may use either English or symbols, but make your use of quantifier proof rules clear.

• (c, 10) Prove the negation of either Statement V or Statement VI from Statements I-IV. (You will find this easier if you choose the negation of the statement that is actually false.) You may use either English or symbols, but make your use of quantifier proof rules clear.

• Question 4 (30): This question uses the functions f, p, q, and r from N to N, and the DFA D, defined above. Recall that for any natural n, p(n) is the number of strings w of length n such that δ*(p, w) = p, and that q(n) and r(n) are defined similarly (with p still used as the start state).

• (a, 10) Recall that f is defined by the rules f(0) = 0 and, for all naturals n, f(n+1) = 2f(n) + n. Prove by induction that for every natural n, f(n) = 2n - n - 1.

• (b, 5) Compute the value of p(n), q(n), and r(n) for all n with 0 ≤ n ≤ 4.

• (c, 5) Explain why for any natural n, r(n+1) = 2r(n) + q(n). Your explanation should refer specifically to the DFA D.

• (d, 10) Let Z(n) be the statement "(p(n) = 1) ∧ (q(n) = n) ∧ (r(n) = 2n - n - 1)". Prove that Z(n) is true for all naturals n, by ordinary induction on n.

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

• (a, 10) Use the construction from lecture and the text to obtain a regular expression denoting the language of D. Do not simplify your expression -- I want the one from the construction.

• (b, 5) Use the construction from lecture and the text to find a λ-NFA whose language is denoted by the regular expression from part (a). (N is such a λ-NFA, but I want the one from the construction.)

• (c, 10) Using the construction given in lecture and in the text, find an ordinary NFA N' such that L(N') = L(N). (Use N rather than your answer from (b) == it will be easier.)

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

• (e, 5) Either prove that your D' is minimal or prove that it is not minimal. (If it is not minimal, you are not required to minimize it.)