# Second Midterm Exam Spring 2020

### Directions:

• Answer the problems on the exam pages.
• There are four problems, each with multiple parts, for 100 total points plus 10 extra credit. Actual scale A = 95, C = 65.
• 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: 15 points
Q2: 20+10 points
Q3: 35 points
Q4: 30 points
Total: 100+10 points
```

• Question 1 (15): Define the function G from naturals to naturals recursively, by the rules G(0) = 0, G(1) = 1, and, for all n with n ≥ 1, G(n+1) = 5G(n) - 6G(n-1). Prove, by strong induction, that for all naturals n, G(n) = 3n - 2n.

• Question 2 (20+10): These questions deal with a language L over the alphabet {a, b, c, d}, and a related set T of rooted trees with leaves labeled by letters from that alphabet. Both are defined recursively. The rules for L are:

1. b is in L.
2. If w is a string in L, then awc is in L.
3. If u and v are both strings in L, then udv is in L.
4. The only strings in L are those made using the first three rules.

The rules for T are:

1. A single node labeled by b is in T.
2. If t is a tree in T, then the tree that has a root with three children: a leaf labeled a, t, and a leaf labeled c, is in T.
3. If t and u are trees in T, then the three that has a root with three children: t, a leaf labeled d, and u, is in T.
4. The only trees in T are those made using the first three rules.

• (a, 5) Prove by induction on all naturals n that the string anbcn is in L. (For example, if n = 3 this string is aaabccc.)

• (b, 5) For any positive natural n, define wn to be the string of length 2n - 1 that starts with b and alternates b's and d's. (For example, if n = 3 this string is bdbdbdb.) Prove, by induction on all positive naturals n, that wn is in L.

• (c, 10) Prove, by induction on the definition of L, that every string in L has odd length.

• (d, 10XC) Prove, by induction on both definitions in the question, that a string is in L if and only if it is the string formed by reading the leaves of a tree in T from left to right.

• Question 3 (35): These questions involve the following weighted undirected graph. The numbers in the middle of the edges give edge weights. The numbers in parentheses at each node are weights for the A* search in part (e).

``````
q(7)
/   \
1     1
/         \
r(6)        s(8)
|           |
1           3
|           |
t(5)        u(6)
\        /  \
2      3    2
\   /        \
v(3)        w(5)
|            |
2            3
|            |
x(1)         y(2)
\       /
2     2
\  /
z(0)

``````

• (a, 5) Carry out a depth-first search of G with start node s and no goal node. Indicate the stack contents at each step. If two nodes enter the stack at the same time, they should come off in alphabetical order. Draw the DFS tree, including non-tree edges.

• (b, 5) Carry out a breadth-first search of G with start node s and no goal node. Indicate the queue contents at each step. If two nodes enter the queue at the same time, they should come off in alphabetical order. Draw the BFS tree, including non-tree edges.

• (c, 5) Prove that if we conduct either a DFS or a BFS of G, with any choice of start node and no goal node, then the resulting tree will have exactly two non-tree edges.

• (d, 10) Carry out a uniform-cost search of G with start node s and goal node z, using the given edge weights. Indicate which nodes are on the priority queue at each stage of the search.
• (e, 10) Conduct a complete A* search of G with start node s and goal node z, using the given edge weights and the given values for the heuristic function h. Indicate which nodes are on the priority queue at each stage of the search.

• 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) Any undirected graph with no cycles is a tree.

• (b) Depth-first search is the same as uniform-cost search with costs of 1 on every edge.

• (c) Let g(s) and h(s) be two admissible heuristic functions for an A* search of the same graph with the same target node. Then the average of the two, (1/2)(g(s) + h(s)), is also an admissible heuristic for that graph with that target node.

• (d) The path relation on a directed graph may fail to be transitive.

• (e) If a rooted tree has exactly one node, then its depth is 1.

• (f) There exists a rooted binary tree T, with a positive even number of nodes, such that every internal node of T has exactly two children.

• (g) Let G be a weighted directed graph with nodes s and t. Let C be a positive constant. It is possible that if we add C to the cost of evere edge in G, then we will change the path from s to t found by a uniform-cost search.

• (h) 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.

• (i) Let P(n) be a predicate on naturals. If P(0) and P(1) are both true, and ∀n: P(n) → (P(2n) ∧ P(2n+1)) is true, then ∀n: P(n) must be true.

• (j) Let G be a two-player deterministic game with perfect information, defined by a finite game tree with real-number values at its leaves. It is possible that G has value x, but that none of the leaves of the tree has value x.

• (k) Let Q(w) be a predicate on binary strings. It is possible that Q(λ) and ∀w: Q(w) → (Q(w0) ∧ Q(w1)) are both true, but that there exists a string v such that Q(v) is false.

• (l) Let G be a directed graph and let s and t be nodes of G. If we do both a depth-first search and an A* of G with start node s and goal node t, then the A* search is guaranteed to expand no more nodes than the DFS.

• (m) Let G be a strongly connected directed graph, and suppose we conduct a DFS of G from start node s. If we remove all the back edges from the resulting DFS tree, the remaining edges form an acyclic graph.

• (n) Let (u, v) be a non-tree edge of the BFS tree of a strongly connected directed graph. If u is at level 5 of the tree, then it is possible that v is at level 2 or at level 6, but not possible that v is at level 7.

• (o) The set of integers {0,1,2,3,4,5,6}, with successor, addition, and multiplication all defined modulo 7, does not model the Peano axioms.