Question text is in black, solutions in blue.
Q1: 20+10 points Q2: 30 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,...}.
The Fibonacci numbers are a sequence of naturals defined by the rules F(0) = 0, F(1) = 1, and, for all n with n ≥ 1, F(n+1) = F(n) + F(n-1).
For every natural n, we define two graphs, a directed graph Dn and an undirected graph Un. Each has vertex set {0, 1,..., n}. The directed edges of Dn are (1) (i, i+1) for every i with 0 ≤ i ≤ n-1, (2) (i+2, i) for every even i with 0 ≤ i ≤ n-2, and (3) (i, i+2) for every odd with 1 ≤ i ≤ n-2.
We also view Dn as a labeled graph where each edge of type (1) above has cost 2, and the other edges have cost 3.
The undirected graph Un has the same vertex set as Dn, and an undirected edge whenever Dn has a directed edge. We will not have occasion to use edge costs in Un.
Directed graph D_5 with edge costs. The graph U_5 has the
same nodes and edges but all the edges are undirected.
___________ _____________
/ 3 \ / 3 \
V \ V \
(0) ----> (1) ----> (2) ----> (3) ----> (4) ----> (5)
2 \ 2 2 ^ \ 2 2 ^
\______________/ \_____________ /
3 3
Base case: W(0) and W(1) are given to be 350. Note that two base
cases are needed for the strong induction.
Strong inductive hypothesis: W(i) = 350 for all i with i ≤ n
Inductive goal: W(n+1) = 350
Proof: W(n+1), by the given rule, is W(n)√2 - W(n-1) + 700
- 350√n, which by the SIH is 350√2 - 350 + 700 -
350√2 = 350.
W(0) = 350
W(1) = 400
W(2) = 400√2 - 350 + 700 - 350√2 = 350 + 50√2
W(3) = (350 + 50√2)√2 - 400 + 700 - 350√2 =
400
W(4) = 400√2 - (350 + 50√2) + 700 - 350√2 =
350
W(5) = 350√2 - 400 + 700 - 350√2 = 300
W(6) = 300√2 - 350 + 700 - 350√2 = 350 - 50√2
W(7) = (350 - 50√2)√2 - 300 + 700 - 350√2 =
300
W(8) = 300√2 - (350 - 50√2) + 700 - 350√2 =
350
W(9) = 350√2 - 300 + 700 - 350√2 = 400
W(10) = 350 + 50√2 by the same calculation as W(2)
Base case: a0 = 350, a1 = 400, b0 =
b1 = 0. Note that two base cases are needed for the
strong induction.
Strong IH: ai and bi exist for all i with
0 ≤ i ≤ n.
Inductive goal: an+1 and bn+1 exist.
Proof: W(n+1) = (an + bn√2)√2
- (an-1 + bn-1√2) + 700 - 350√2 =
(2bn - an-1 + 700) + (an +
bn-1 - 350)√2. Thus W(n+1) is of the required form,
as the integers are closed under addition and multiplication by 2.
The integers are not closed under multiplication by √2,
so the proof has to note somehow that when we multiply a number of the
form a + b√2 by √2, we get some number c + d√2.
A number of you claimed a solution for this problem based on an
incomplete or invalid proof of the true fact that the values of W(n)
cycle with period 8. I gave substantial credit for this, but not full credit.
The key fact, as many of you observed but fewer of you proved, is that
the values of W(n) cycle with period 8, so that W(n) = W(n%8) in Java
notation.
Once we know this, we see that W(84) is equal to W(4), which we
computed in part (b) to be 350.
How to prove that the cycle exists? We let our statement P(n) be
"W(n) = W(n%8)". We can observe the base cases for n ≤ 10 from
part (b). Our SIH is that W(i) = W(i%8) for all i with i ≤ n,
and the inductive goal is to prove that W(n+1) = W((n+1)%8). The
rule tells us that W(n+1) depends on W(n) and W(n-1), and the SIH
lets us replace W(n) and W(n-1) by W(n%8) and W((n-1)%8. Finally
the rule lets us take the expression in W(n%8) and W((n-1)%8) and
convert it to W((n+1)%8), proving the inductive goal.
It is possible to prove that W(n+8) = W(n) by eight applications of
the rule, and this is enough to prove that W(84) = W(4). Easier is
to prove that W(n+4) = 700 - W(0), by four applications of the rule.
First base: n = 0, there is one empty path from 0 to 0, F(0+1) = 1.
Second base: n = 1, there is one path from 0 to 1 using the
single edge (0, 1), F(1+1) = 1. Note that we need two base cases
for the strong induction.
SIH: For each i with i ≤ n, there are F(i+1) paths from 0 to
i.
Inductive goal: There are F(n+2) paths from 0 to n+1.
Proof: Any path from 0 to n+1 must get to n+1 using either the
edge from n or the edge from n-1. There are F(n+1) paths doing
the former and F(n) paths doing the latter, by the SIH. By the
Fibonacci rule, the total number F(n+1) + F(n) is equal to F(n+2).
First base: n = 1 (since the induction is on positive naturals) The
only path has cost 2, and 2 = (3(1) + 1)/2.
Second base: n = 2, the only path has cost 4, and 4 = (3(2)/2)
+ 1.
SIH: The best path to each vertex i with i ≤ n has the given
cost.
Inductive goal: The best path to vertex n+1 has the given cost.
Proof: If n is odd and n+1 is even, the only edge into n+1 is
from n, so any path to n+1 takes a path to n and then an edge of
cost 2. Since the best path to n has cost (3n+1)/2, the best path
to n+1 has cost (3n+1)/2 + 2 = (3n+5)/2 = 3(n+1)/2 + 1, as given
by the formula for even numbers.
If n is even and n+1 is odd, there are two edges into n+1, one
from n and one from n-1. Applying the SIH, the cost of the best path
to n+1 is the lesser of 3 + (3(n-1) + 1)/2 and 2 + (3n/2 +
1)/2,
which is (3n + 4)/2 as opposed to (3n+6)/2. This is equal to the
odd-case
formula for n+1, which is (3(n+1) + 1)/2. I did not give full credit
unless you proved that the path was optimal, by considering the
multiple options for a path into an odd-numbered vertex.
Node 3 goes on the queue. Node 3 comes off, and nodes 1, 2, 4, and 5
go on. Node 1 comes off, and nodes 0 and 2 go on. Node 2 (the
first copy, from 3) comes off, and nodes 0 and 4 go on. Node 4
(the first copy, from 3) comes off, and node 5 goes on. Node 5
comes off, and nothing goes on.
Node 0 comes off (the copy from 1) and nothing goes on.
The remaining nodes are discarded
as they are all on the closed list.
In the tree, 3 is the root, with children 1, 2, 4, and 5, and 1
has a child 0. The four non-tree edges are (0, 2), (1, 2), (2, 4),
and (4, 5).
Node 3 goes on the stack. Node 3 comes off, and 4 and 5 go on. 4 comes
off, and 2 and 5 go on.
Note that there are now two copies of 5 on the stack, because 5 is
not yet on the closed list. The copy closer to the top is the one
from 4.
Node 2 comes off, and node 0 goes on (3 is on the closed list).
Node 0 comes off, and 1 goes on. Node 1 comes off, and nothing
goes on because 2 and 3 are on the closed list.
Now the copy of 5 from 4 comes off, and nothing goes on. The
second copy of 5 is discarded, emptying the stack and finishing the
search.
Node 3 is the root of the DFS tree, with a tree edge to 4 and a
forward edge to 5. Node 4 has tree edges to its two children, 2 and
5. Node 2 has a tree edge to 0 and a back edge to 3. Node 0 has a
tree edge to 1. Node 1 has back edges to 2 and 3.
We will denote items on the PQ as pairs of the form (node number, priority).
(3, 0) goes on the PQ. It comes off, and (4, 2) and (5, 3) go on.
(4, 2) comes off, and (2, 5) and (5, 4) go on. (5, 3) comes off, and
nothing goes on. (5, 4) is discarded because 5 is on the closed list.
(2, 5) comes off, and (0, 8) goes on (3 is on the closed list). (0,
8) comes off and (1, 10) goes on. (1, 10) comes off and we declare
victory.
We have found the path 3-4-2-0-1, of cost 10.
We denote items on the PQ by pairs of the form (node number, cost +
heuristic).
To begin, (3, 0+2) goes on. It comes off, and (4, 2+3) and (5, 3+4)
go on. (4, 2+3) comes off, and (2, 5+1) and (5, 4+4) go on. (2, 5+1)
comes off and (0, 8+1) goes on (3 is on the closed list). (5, 3+4)
comes off and nothing goes on. (5, 4+4) is discarded as 5 is on the
closed list. (0, 8+1) comes off and (1, 10+0) goes on. (1, 10+0)
comes off and we declare victory.
We found the same path as in part (c) and actually did the same
operations -- the only difference is that we explored 2 before 5 in
the A* search because 2's heuristic was smaller.
FALSE. If W(0) = W(1) = 0, for example, W(2) = 700 - 350√2 ≠ 0.
FALSE. I had intended this to be true, but got the numbers wrong. If
the formula were true, f(0) would be 4 but f(1) would be (1 - 5 +
8)/2 = 2, while the recursive definiton gives f(1) = f(0) + 0 - 3 =
1.
The correct closed form of this recurrence is (n2 - 7n + 8)/2.
FALSE. The fifth axiom says that if you start at 0 and keep taking
successors, you will reach all the numbers, and that is true in this system.
TRUE. E(2, 3) ≠ E(3, 2), and E(2, E(3, 2)) ≠ E(E(2, 3), 2). I
see that I asked this same question in Spring 2017.
TRUE. If a string does not have either of those two substrings, it
must alternate 0's and 1's, and so if it has odd length its first
and last letter will be the same.
TRUE. We can always reach every node from 0, and reach n from any
node,
so we are strongly
connected if and only if we can reach 0 from n. If n is even we can
do so with the backwards edges. But if n is odd there is no edge
out of node n and thus cannot reach 0 from it.
TRUE. The graphs U0 and U1 are clearly
bipartite.
But all the other Un's contain a triangle with nodes 0, 1,
and 2, and these three nodes cannot be split into two groups without
an edge between two nodes in the same group.
FALSE. The correct number is k(k-1)n-1, because we may
choose any of the k letters to start and then have k-1 choices for
each subsequent letter. Actually I neglected to specify that n should
be positive, so the statement is also false because it gives (k-1)/k
instead of 1 for n = 0.
FALSE. It has one more leaf than its number of internal nodes.
TRUE. The generic search does not recognize previously seen nodes
unless we say it does, so it could get caught in an infinite loop.
TRUE. It turns out to be admissible, actually, but h(2) = 2, h(4) =
6, and there is an edge from 4 to 2 with cost 3, violating the
consistency condition.
FALSE. It has one leaf, because this method only calls itself at most
once per iteration So the call tree has a single branch and a single leaf.
TRUE. This would be false if there were only binary operators, but
the expression "NOT NOT 0", for example, has two operators and only
one primitive expression.
FALSE. There could be a high value in the right subtree that does not
figure into the value of the game because the second player can avoid
it being the result of the game.
TRUE. If both players play their optimal strategy, the result will be
v, so they must reach a leaf with v as its leaf value.
factorial
method has n-1 leaves for any input n with n > 1.
Last modified 26 November 2017