CMPSCI 250: Introduction to Computation
Second Midterm Exam Spring 2016
David Mix Barrington
30 March 2016
Directions:
- Answer the problems on the exam pages.
- There are four problems, some with multiple parts, for 100 total
points plus 10 extra credit. Actual scale A = 93, C = 66.
- 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: 15 points
Q3: 40 points
Q4: 25+10 points
Total: 100+10 points
Here are definitions of some terms, sets, predicates, and statements used
on this exam.
Remember that the scope of any quantifier is always to the end of
the statement it is in.
Remember that a natural is a non-negative integer, so that
the set N or all naturals is {0, 1, 2, 3,...}.
A binary string is a string over the alphabet {0, 1}, and
the
reversal wR of a binary string w is defined by the
rules
λR = λ and (wa)R = awR.
An undirected graph is said to be bipartite if it is
possible to partition its nodes into two sets R and B, such that every
edge of the graph has one endpoint in R and one in B. Equivalently,
the
nodes may be colored red and blue such that no edge connects red to
red or blue to blue.
On a two-dimensional grid, the Manhattan distance between
two points (a, b) and (c, d) is the minimum length of any path from
one point to the other that follows the edges of the grid, that is,
|a - c| + |b - d|.
The following scenario is used in Question 4. On a shelf in our
house there are two containers of dog treats, one with large treats
for Cardie and one with small treats for Duncan. Every day Cardie
gets five large treats and Duncan gets seven small treats. If there
are fewer than 20 large treats in Cardie's container at the beginning
of the day, we add 48 more. If there are fewer than 20 small treats
in Duncan's container at the beginning of the day, we add 90 more.
(For example, suppose there are 23 treats in Cardie's container at the
start of Day 0. Then there are 23 - 5 = 18 there at the start of Day
1, and 18 + 48 - 5 = 61 at the start of Day 2.
The function c(n) denotes the number of treats in Cardie's
container
at the start of Day n, and the function d(n) denotes the number of
treats in Duncan's container at the start of Day n.
The n by n knight graph has an n by n square array of nodes,
labeled as in chess positions with rows 1, 2,..., n and columns a,
b,..., so the for example node d3 is in the third row and the fourth
column. There is an undirected edge between two nodes whenever a
chess knight can move from one to the other. (Chess knights move
either two squares horizontally and one vertically, or one
horizontally and two vertically.
This page
shows pictures of the 3 by 3, 4 by 4, 5 by 5, and 6 by 6 knight
graphs.
(Note that neither the 1 by 1 nor the 2 by 2 knight graphs have any edges at
all.) The 3 by 3 knight graph has 8 edges, and the 4 by 4 knight graph
has 24.
Thus if f(n) is the number of edges in the n by n knight graph, we
have all the values for n ≤ 4. By an analysis we won't explain
here, for all n with n ≥ 4, f(n+1) is equal to f(n) + 20 + 4(2n -
7).
You will need this formula for Question 2.
This
page has a 4 by 4 knight graph with labels, which are not exactly
the labels we are using. We are calling the nodes a1, a2,..., d4, and
we will normally put the a nodes in a column rather than a row, but
the 4 by 4 kn1ght graph you will search in Question 3 otherwise looks
the same as this one.
- Question 1 (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 a rooted tree has only one node, its depth is 1.
- (b) Define a binary predicate X(i, j) on the naturals as
follows. X(0, 0) is false, x(0, k) is true whenever k ≠ 0, and
X(i+1, j+1) always has the same value as X(i, j). Then for any i
and j, it must be true that X(i, j) is true if and only if i ≠ j.
- (c) If an undirected graph with n nodes has fewer than n
edges, it cannot have a cycle.
- (d) For any binary strings u and v,
(uRvR)R = uv.
- (e) A generic search may continue after a goal node has been
put on its open list.
- (f) Let G be a two-player deterministic game with perfect
information and 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.
- (g) Let G be a game as in part (f), where White (who wants
the game result to be as large as possible) has the first move, and
every leaf in the left subtree of the root node has value at least
x. Then the value of the game is at least x.
- (h) 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. (Recall that a node of such a tree is called an
internal node if and only if it is not a leaf.
- (i) Let P(w) be a predicate with one free variable w of type
"binary string". It is possible that P(λ) is true and that
P(w) implies ((P(w0) ∧ P(w1)) for any string w, but that there
exists a string v sich that P(v) is false.
- (j) For every positive natural n, there is an arithmetic
expression En such that (1) the only operators of
En
are + and ×, (2) the only atomic values of En are
prime numbers, and (3) En evaluates to n. (Note that the
empty string λ is not an arithmetic expression.)
- Question 2 (15): Let f(n) be the number of edges in the
n by n knight graph, as defined above. Prove that for all naturals n
with n ≥ 1, f(n) = 4(n - 1)(n - 2). (Hint: Check enough base
cases until you can use the formula given above for your inductive step.)
- Question 3 (40): These questions all involve searches of
the 4 by 4 knight graph, defined above. Its sixteen nodes are
labeled a1, a2,..., d3, d4.
- (a, 5) Carry out a depth-first search of the graph with start
node a1 and goal node c3. Assume that once a node has been put on
the open list, it is recognized and not put on the open list again.
- (b, 5) Carry out a breadth-first search of the graph with
start node a1 and goal node c3. As in part (a), assume that once
a node has ben put on the open list, it is recognized and not put
on the open list again.
- (c, 15) Carry out another breadth-first search of the
graph with start node a1, but this time with no goal node. (You
may refer to your work in part (b) and use it without copying it.)
Redraw the graph as a BFS tree, indicating both tree and non-tree edges.
- (d, 5) Recall the definition of a bipartite graph
given above. Is the 4 by 4 knight graph bipartite? How can you
tell that it is our isn't, given the BFS tree from part (c)?
- (e, 10) Label the edges of the 4 by 4 knight graph such
that edges that go two steps vertically, such as from a1 to b3,
are labeled 3, and edges that go two steps horizontally, such as
from
a1 to c2, are labeled 5. Conduct a uniform-cost search of the
weighted graph, with start node a1 and goal node c3.
- (f, 5) Suppose we want to convert our uniform-cost search
of the labeled graph of part (e) into an A* search.
Would Manhattan distance (as defined above) from c3 be a suitable
heuristic? Why or why not?
- Question 4 (25+10): These questions involve the dog
treat scenario defined above.
Last modified 10 April 2016