Exam text is in black, solutions in blue.
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)
For the base case of n = 1, s1 is 3 because Duncan gets one treat
and Cardie gets two. This matches the given formula because
21+1 + 1 - 2 = 3. Note that to prove the base case, you
need to determine both s1 and the value given by the
formula, and show that they are the same.
For the inductive case, we have that sn+1 =
sn + cn+1 + dn+1. We know that
sn = 2n+1 + n - 2 from the inductive
hypothesis, so what we need is cn+1 and dn+1.
We are not given these quantities directly, but we are given
recurrence information that lets us determine them. For full
credit, I wanted a proof that the numbers you used for these two
quantities were correct. Since we are given that d1 = 1
and dn+1 = 2dn, we can prove that
di = 2i-1 for any i: for the base case
21-1 = 1, and given that dn = 2n-1
from the IH, dn+1 = 2n follows from the
recurrence for di.
Once we know that dn+1 = 2n, and
consequently cn+1 = 2n + 1, we can calculate
sn+1 = sn + cn+1 + dn+1
= 2n+1 + n - 2 + 2n + 1 + 2n =
2n+2 + (n+1) - 2, matching the formula for
sn+1.
This completes the induction and the proof.
Again the base case of n = 1 has one treat for Duncan and two for
Cardie, and 12 + 2(1) = 3 so this matches the formula.
For the inductive case, we need a formula for di, and we
are given that d1 = 1 and dn+1 = dn
+ 1. This lets us prove di = i by induction. The base
case
is clear, and dn+1 = n+1 follows from the IH of
dn = n by the rule for d. And of course we now know that
ci = i + 1 for any i.
Now we can calculate sn+1 = sn +
cn+1 + dn+1 = n2 + 2n + (n+1) + n =
n2 + 4n + 3 = (n+1)2 + 2(n+1). This completes
the induction and the proof.
We begin with a on the stack. We pop a and push its neighbors b and
c, making the stack (b, c). We pop b and push its neighbors c, d,
and e, making the stack (c, d, e, c). We pop c and push its
neighbors f and g, making the stack (f, g, d, e, c). We pop f and
push its neighbor g, making the stack (g, g, d, e, c). We pop g
and push nothing. We pop g again, discovering the forward edge
from c to g. We pop d and push its neighbor e, making the stack
(e, e, c). We pop e and push nothing. We pop e again, discovering
the forward edge from b to e. Finally we pop c, discovering the
forward edge from a to c.
In our depth-first search, a node is marked as closed, or put on
the closed list, once it has come off the open list. So it
is important that c, for example, is put on the open list a second
time when it is found from b, and that this entry for c is
the one that is processed later. Thus the edge from b to c becomes
a tree and not a cross edge.
Many people had a different conception of the stack behavior in
which node a was put on at the beginning and not popped to the end.
This corresponds to the method stack in a recursive implementation
of DFS, but not to the DFS from this course, which is defined in
terms of our generic search.
Root node a has only child b, which has children c and d. Node c has
only child f and grandchild g, while node e has child e. That gives
all six tree edges -- as noted above, the three forward edges are (a,
c), (b, e), and (c, g). There are no back or cross edges in this
search.
If you did the search without putting nodes on the open list for
the second time, the search tree has node a with children b and c,
and grandchildren d, e, f, and g, with cross edges (b, c), (d, e),
and (f, g). I gave full credit for this tree if you did the
search that way, though of course in that case you did not get full
credit in part (a).
For the base case, G0 has no edges, and the formula gives
3(20 - 1) = 0. Again, a correct base case states both
these numbers and notes that they are the same.
By the definition of Gn+1, its number of edges is 3,
plus twice the number of edges in Gn. This latter number
is 3(2n - 1) by the IH, so the new number is 3 +
2(3(2n - 1) = 3(2n+1 - 1) as the formula says.
This completes the induction and the proof.
There are other relationships between Gn and
Gn+1 besides the one given by the definition. For
example, Gn+1 can be made from Gn by adding
three-edge triangles to each of its 2n leaves, and this
is the basis of an induction proof that many of you gave for this
question. The problem with that proof is that the inductive step
depends on properties of the Gn's that you have not
proved from the definition, in contrast to the proof above that uses
only the definition. How do you know that there are exactly
2n leaves in Gn? Or that the first n levels
of Gn+1 are the same graph as Gn?
This was a challenging problem in part because the fact it proves is
almost obvious. The question is why, given the definition of
the
graph family, it has to be true.
The base case of the induction is simple. With n = 0, there are no
edges, and so the longest path is the empty path from the root to
itself. This path has length 0, which is what we want since 2n here
is 0.
For the inductive case, though, proceeding in the simplest way runs
into problems. Suppose we take P(n) to be just "the longest path is
of length 2n". The IH tells us that there is a path of length 2n in
Gn, and no longer path. But it doesn't tell us where
that path goes, so we cannot yet say that there is a longer path
using the three new edges.
A better P(n) is "there is a path from the root of Gn of
length 2n, and no path anywhere in Gn of length longer
than 2n". If we have this statement as our IH, we can say first
that we can make a path of length 2n+2 from the root of
Gn+1, by taking the edge from the new root to one old
root, then the edge to the other old root, then following the
assumed path inside of that copy of Gn. This path
exists, so we have only to show that there is no longer path. Once
a path in Gn+1 takes an edge other than one of the three
new edges, it cannot leave the copy of Gn containing that
edge. So any path in Gn+1 must be in one of those
copies, except perhaps for some of the three new edges. At most two
of those can be put into any path, and by assumption we can have at
most 2n edges within the Gn, so the path can have at most
2n+2 edges. This completes the induction and the proof.
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.)
We'll assume here that nodes entering the queue at the same time come
off in alphabetical order, though that was not a condition of the
problem.
The tree has sixteen tree edges and nine non-tree edges. We
can find them from the trace above by seeing where the first
copy of each node on the queue comes from: (g, m), (g, o), (g,
p), (m, j), (m. k), (m, l), (p, n), (j, d), (j, e), (j, f),
(k, h), (l, i), (d, a), (e, b), (f, c), (a, s). The nine other
edges are non-tree: (o, l), (n, k), (j, k), (k, f), (k, h), (i, d), (h,
c), (b, s), (c, s).
The h values are given by the levels of this tree, since it
finds the path with the fewest edges between g and each node x, and
this path is an optimal one for the Hulk since all edges are the
same cost for him. We have h(x) = 0 for x = g, h(x) = 1 for x = m,
o, or p, h(x) = 2 for x = j, k, l, or n, h(x) = 3 for x = d, e, f,
h, or i, h(x) = 4 for x = a, b, or c, and h(s) = 5.
Note that there is no particular reason one node with minimum
value should come off the PQ before another, so there is more than
one correct sequence of moves. But nodes must come off the PQ in
order of smallest distance from the start node.
FALSE. Both are true, since 20+1 + 0 - 2 and 02
+ 2(0) both evaluate to 0, and the sums also evaluate to 0 when n =
0 because there are no terms to be added.
TRUE. Q(n) can be taken to be the statement ∀i: (i ≤ n)
→ P(i). The inductive step of an ordinary induction proof of
∀n:Q(n) is just the strong inductive step for the strong
induction proof of ∀n:P(n). And clearly Q(n) implies P(n)
for any n, since we can specify the universal quantifier in Q(n) to
i = n to get "(n ≤ n) → P(n)", which clearly implies P(n).
TRUE. This function deletes all the zeroes in w, and places a single
0 at the start. This creates 011 from 10010.
TRUE. The similar statement in the definition of addition is
∀x:∀y:x + S(y) = S(x + y).
FALSE. A node can go on the open list only when a node with an edge
to it is processed. Thus the n'th node to come off the list must be
at the end of a path from s, of length at most n-1. But the shortest
path in OC from s to g has length 5, so that g must be the sixth or
later node off of the list.
FALSE. It has lots of triangles (sets of three nodes with edges
between each pair). A triangle is a 3-cycle, and a bipartite graph
can not have any cycles of odd length.
TRUE. Any connected undirected graph has this property. Cross and
forward edges only occur in a DFS of a directed graph.
FALSE. The correct DFS search from 2(a) reaches node c from node b,
while the BFS finds c from node a.
TRUE. By induction on n, it is easy to show that Gn has no
directed cycles. The base for n = 0 is clear, and once any path in
Gn+1 enters one of the copies of Gn, it cannot
leave, and by the IH it cannot revisit any node within that copy. And
clearly there is no cycle that does not enter one of the two Gn's.
FALSE. G0 is a rooted tree, though none of the others are.
TRUE. An infinite search can only occur when the directed graph has a
directed cycle, which none of the Gn's do.
TRUE. Any function based on a distance will be consistent. It is
admissible because for any node x, the human time from x to g must be
at least twice the Hulk's time, as the human takes at least two
minutes for each edge.
FALSE. It will be consistent but not admissible. A human can reach g
from p in two minutes, but 4h(p) is 4.
FALSE. Each player can avoid the worst outcome for them with their
single choice, and their optimal strategy is certainly to do this. So
the result of the game under optimal play by both cannot be 1 or 4,
only 2 or 3.
FALSE. Black has a winning strategy. If he moves 1 on his first move
and 0 on his third move, the string will be *1***0, with some bit
replacing each of the four stars. This is an even number greater than
2, and cannot be prime.
Last modified 22 April 2018