# Second Midterm Exam Spring 2018

### 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 was A = 90, C = 60.
• 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: 20 points
Q2: 20+10 points
Q3: 30 points
Q4: 30 points
Total: 100+10 points
```

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

Remember that a natural is a non-negative integer, so that the set N or all naturals is {0, 1, 2, 3,...}.

For every natural n, we define a directed graph Gn as follows. G0 has a single node with no edges, and we will call that one node its root. For any natural n, Gn+1 consists of two copies of Gn, one new node which is the root of Gn+1, and three new edges -- one from the new root to the root of each of the Gn's, and one from one of the Gn roots to the other.

``````
Directed graphs G_0, G_1, G_2, G_3.  "V" and ">" are arrowheads.

G_0   a     G_1     a      G_2          a
/ \                 / \
V   V               V   V
b --> c             b --> c
/ \   / \
V   V V   V
d -> e f -> g

G_3                a
/ \
/   \
/     \
/       \
V         V
b --------> c
/ \         / \
V   V       V   V
d --> e     f --> g
/ \   / \   / \   / \
V   V V   V V   V V   V
h -> i j ->k l-> m n -> o

``````

The labeled undirected graph OC represents an imagined orienteering course, with seventeen nodes and 25 edges. Each edge is labeled "run", "walk", or "fight", indicating that it takes two, four, or six minutes respectively for an ordinary human competitor to traverse the edge.

``````
Map of orienteering course -- edges are run (r), walk (w), or fight
(f). Normal human competitors take 2 minutes to run, 4 to walk,
6 to fight.  The Hulk takes 1 minute to traverse any edge.

(a)--r--(d)--w--(i)--f--(l)--w--(o)
/            \             |       |
r                f           f       w
/                   \         |       |
(s)--w--(b)--w--(e)--f--(j)--w--(m)--w--(g)
\                   / |     /         |
r               f   f   f           r
\           /     | /             |
(c)--f--(f)--f--(k)--r--(n)--f--(p)
\     |     /
w   w   w
\ | /
(h)

``````

• Question 1 (20+10): I need a new plan to allocate treats to my dogs, Cardie and Duncan. On day i, starting with day 1, I will give ci treats to Cardie and di treats to Duncan. For any natural n, I need to calculate the sum sn = ∑i=in (ci + di), the total number of treats I will need to supply both dogs for the first n days of the plan.

• (a, 10) Duncan proposes that he gets one treat on day 1, and twice as many each succeeding day as on the day before, so that di+1 = 2di for all positive n. Cardie proposes that she get one more treat than Duncan on each day, so that ci = di + 1 for all positive i. Prove by induction for all positive naturals n that under this plan, sn = 2n+1 + n - 2.

• (b, 10) My counterproposal is that Duncan gets one treat on day 1 and one more on each succeeding day, so that di+1 = di + 1 for all positive i. Cardie again gets one more treat than Duncan each day, so that ci = di + 1 for all positive i. Prove by induction for all positive naturals n that under this plan, sn = n2 + 2n.

• Question 2 (20): The directed graph family Gn is defined above, whith diagrams of Gi for i ≤ 3. G0 has a single node with no edges, and we will call the one node its root. For any natural n, Gn+1 consists of two copies of Gn, one new node which is the root of Gn+1, and three new edges -- one from the new root to the root of each of the Gn's, and one from one of the Gn roots to the other.

• (a, 5) Carry out a depth-first search, recognizing previously seen nodes, for the directed graph G2 with the nodes labeled {a, b, c, d, e, f, g} as above, with start node a and no goal node. When two nodes go on the open list at the same time, they should come out in alphabetical order, with the node earlier in the alphabet coming out first. Show the contents of the stack at each step of the search.

• (b, 5) Draw the depth-first search tree of the search in part (a). Your tree should contain all nine edges of the original graph, with some marked as tree edges and the others marked as back, forward, or cross edges as appropriate.

• (c, 10) Prove by induction on all naturals n that the graph Gn contains exactly 3(2n - 1) edges.

• (d, 10XC) Prove by induction on all naturals n that the longest path in the graph Gn has exactly 2n edges. You must show both that there is a path of that length, and that there is no longer path. It might be useful to make the endpoints of this path part of your statement P(n), so that you may use facts about those endpoints in your inductive hypothesis.

Question 3 (30): In the sport of orienteering, competitors run from one point to another in a forest, using a map to determine their best choice of route. Above we have an imagined orienteering course, the labeled undirected graph OC. There are seventeen nodes representing points in the forest, and edges indicating where a competitor might travel from one point to another. For ordinary human competitors, an edge labeled "r" (for run) can be traversed in two minutes, an edge labeled "w" (walk) in four, and an edge labeled "f" (fight) in six. Our eventual goal is to determine the optimal route from point s to point g.

The last competitor will be Marvel superhero The Incredible Hulk, who can traverse any edge in one minute. (We will have him run last since he will alter the terrain as he passes through it.)

• (a, 10) For any node x in the graph OC, we are going to define h(x) to be the time that the Hulk would require to run from x to g, Conduct a breadth-first search of OC with start node g and no goal node. Draw the resulting BFS tree, showing all the edges as either tree edges or non-tree edges. Explain how this search gives you the value of h(x) for every node x, and list those values.

• (b, 10) Begin a uniform-cost search of OC with start node s and goal node g, using the human times for the edge costs. Stop your search after you have taken six nodes off of the open list.

• (c, 10) Conduct a complete A* search of OC with start node s and goal node g, using the human times for the edge costs and the Hulk's function h(x), computed in part (a), as a heuristic. 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. Some of them refer to the scenarios of the other problems, and/or the entities defined above. Each one counts two points.

• (a) In both the inductions of Question 1, the statements P(0) are false.

• (b) If ∀n:P(n) can be proved by strong induction, then there exists a statement Q(n) such that ∀n:Q(n) can be proved by ordinary induction, and the statement ∀n:Q(n) → P(n) is true.

• (c) Define the function f from binary strings to binary strings by the rules f(λ) = 0, f(w0) = f(w), and f(w1) = f(w)1. Then f(10010) = 011.

• (d) The statement ∀x:S(0) + x = S(x), where S is the successor function, is not part of the definition of addition but can be proved from that definition using induction.

• (e) It is possible to conduct a generic search of the undirected graph OC, with start node s and goal node g, such that g is the fifth node to come off the open list. (Here s will be the first node to come off the open list.)

• (f) The undirected graph OC is bipartite.

• (g) If we create a DFS tree for a search of the undirected graph OC with start node s, every edge will become either a tree edge or a back edge.

• (h) If we conduct a breadth-first search of the directed graph G2, with start node a and no goal node, we will get the same tree edges as in the DFS search of question 2 part (a).

• (i) For every natural n, the graph Gn is a directed acyclic graph.

• (j) For every natural n, the graph Gn is not a tree.

• (k) For any natural n, any generic search of the graph Gn from any start node will eventually terminate, even if previously seen nodes are not recognized.

• (l) The function 2h(x) would be an admissible and consistent heuristic for an A* of graph OC with goal node g.

• (m) The function 2h(x) would be an admissible and consistent heuristic for an A* of graph OC with goal node g.

• (n) Consider a game where White chooses "left" or "right", then Black chooses "left" or "right", then the game ends. The four leaves of the game tree are labeled 1, 2, 3, and 4 in some order. Then for each number x from 1 through 4, it is possible to label the game tree to make x the value of the game, where White wants a large number and Black a small one.

• (o) Consider a game where White and Black alternately name bits (0 or 1) until each has named three bits and they have formed a binary string of length six. White wins the game if the resulting string represents a prime number (possibly with leading zeroes). Then White has a winning strategy for this game.