CMPSCI 250: Introduction to Computation
Second Midterm Exam
David Mix Barrington
4 November 2013
Directions:
- Answer the problems on the exam pages.
- There are five problems, some with multiple parts, for 100 total
points plus 10 extra credit. Actual scale A = 93, C = 63, but
may
be adjusted.
- 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: 10 points
Q2: 15 points
Q3: 15+10 points
Q4: 30 points
Q5: 30 points
Total: 100+10 points
Definitions and Other Notes:
N is the set of naturals, {0, 1, 2, 3,...}.
Question 3 uses an inductively defined function from {a,
b}*
to N. We define f(λ) = 0, and for any string w we
define
f(wa) = f(w) + 1 and f(wb) = 2f(w).
Question 4 uses the following inductive definition of "set
expression":
- An atomic set expression has a value that is a set of
int
values.
- If E and F are set expressions, so are E ∪ F, E ∩ F,
and E-bar, denoting the union of E and F, the intersection of E and
F, and the complement of E respectively.
- Nothing else is a set expression.
Question 4 assumes that we have defined a real-Java class
IntSet
whose objects are sets of int
values. The only method of this class that you will need is
public boolean isIn (int x)
, which returns
true
if and only if the int
value
x
is in the calling set. Note that Question 4 will
ask you to write a different method isIn
, for
the SetExpression
class.
We also have the following real-Java class for set expressions:
public class SetExpression {
public static final int UNION = 1;
public static final int INTERSECTION = 2;
public static final int COMPLEMENT = 3;
boolean isLeaf;
IntSet leafValue;
SetExpression left, right;
int op;
// usual constructors, getters, and setters
Question 5 uses the following labeled undirected graph:
[a] ---1--- [s] ---1--- [f]
| | |
3 6 9
| | |
[b] ---1--- [d] ---1--- [g]
| | |
3 6 9
| | |
[c] ---1--- [e] ---1--- [h]
- Question 1 (10):
Identify each of the following five concepts, giving enough detail to
make it clear that you are familiar with them (2 points each):
- (a, 2) the Fibonacci numbers
- (b, 2) the one's complement of a binary string
- (c, 2) an undirected cycle in an undirected graph
- (d, 2) a heuristic for an A search
- (e, 2) a bipartite graph
- Question 2 (15):
Let R be a binary relation on some set A and assume that R is
transitive.
By the definition of transitivity, if R(x, y) and R(y, z) are
true, then R(x, z) must be true. Suppsoe that x1,
x2,..., xk are any k elements of A, and that
we know that R(xi, xi+1) is true for every i
with i ≤ i < k. Prove that R(x1, xk)
is true. (Hint: Use ordinary induction, with a base case of k = 3.)
- Question 3 (15+10): This question uses the function f
from
{a, b}* to N defined above.
- (a, 5) Evaluate f(aabb), f(baba), and f(abba).
- (b, 10) Prove by induction on all naturals n that
there exists a string w such that f(w) = n.
- (c, 10) Prove that for any natural n, there exists a
string
w such that (1) w never has two a's in a row, and (2) f(w) = n.
(Hint: Use strong induction on all naturals n. If you know that
f(w) = n, how can you get strings whose f values are 2n and 2n
+ 1?
- Question 4 (30): This question uses the definition of
set
expressions and the Java classes
IntSet
and
SetExpression
, all defined above.
- (a, 5) If A denotes the set {2, 3, 7}, B denotes the set
{3, 6, 7}, and C denotes the set {2, 7, 9}, what set is denoted
by the set expression A ∩ (B ∪ C-bar)?
- (b, 15) Write a real-Java method
public boolean
isIn (int x)
for the SetExpression
class.
It should return true
if and only if the
int
value x
is in the set denoted by
the calling SetExpression
object.
- (c, 10) Prove by induction on all set expressions E that
your method returns the correct result when called on E. Note
that to prove somethgin about your method, your answer
has better refer to the code of your method!
- Question 5 (30):
This question uses the undirected graph G pictured above. In
every one of these searches, (1) when two or more nodes go into
the open list at the same time, they come out in
alphabetical order, and (2) a closed list is used so that the
search can recognize nodes that have already been processed,
according to the respective types of search. Each search has
start node s and goal node g.
- (a, 10) Trace the depth-first search from s and draw the
DFS tree, stopping when g has been found. Ignore the edge labels.
- (b, 10) Trace the breadth-first search from s and draw the
BFS tree, stopping when G has been found. Ignore the edge
labels.
- (c, 10) Perform a uniform-cost search of the graph from
s, using the edge labels, and stopping when the algorithm may
conclude that it has found the best-path distance from s to g.
Last modified 11 November 2013