The second midterm for CMPSCI 250 will cover the material since the first midterm: quantifiers and quantifier proofs, induction, and graph theory. Here is a test, made up of questions from my past exams, that approximates the one you will get in length, content, and difficulty. There will be 100 points on your exam, probably with 10 extra credit points as well. A typical scale for one of my exams is 90 = A, 60 = C, but I will decide the scale after grading the exam.
Q1: 25 points Q2: 15 points Q3: 15 points Q4: 25 points Q5: 25 points Total: 105 points
Generalized Fibonacci Numbers:: If a and b are any two naturals, we define the function Ga,b by the rules (1) Ga,b(0) = a, (2) Ga,b(1) = b, and (3) (for n ≥ 1) Ga,b(n+1) = Ga,b(n) + Ga,b(n-1). Note that the ordinary Fibonacci numbers, as defined in Discussion #7, are defined by F(n) = G0,1(n).
Both Questions 2 and 3 are from the Spring 2011 first midterm, solutions here). They use these definitions:
We have a dog play group G, consisting of exactly the four dogs Ace, Biscuit, Cardie, and Duncan, denoted by the constants a, b, c, and d respectively. The variables g, g1, g2, etc., are of type "dog in G". There is also a set of playthings P, which includes a Rope chew r, a Stuffed chicken s, and a Tennis ball t, possibly with other items as well. The variables p, p1, p2, etc., are of type "plaything in P". The predicate H(g, p) means "dog g has plaything p". Unless otherwise indicated, there are no restrictions on a dog having more than one plaything, or more than one dog having the same plaything.
Question 4 deals with a two-player game called Stones. In Stones, there is a single pile with some natural number of stones in it. On her turn, a player must remove either one or two stones from the pile. The first player who cannot move loses. (That is, the player who takes the last stone wins.) The game is somewhat similar to another game called Nim that you may have seen, but Stones is easier to analyze.
Four questions concerning this game:
I have two alternate choices for Question 5, both from the Fall 2011 second midterm with solutions here). I would only include one on an exam of this length. And this term we have done a somewhat different set of graph theory topics so the actual question will be somewhat different.
This question deals with the following real-Java class. An
IntTree
object is a tree where the leaves each store
int
values, so that the entire tree stores a set of
int
values, in no particular order.
public class IntTree {
boolean isLeaf;
int leafValue; // only defined if isLeaf is true
IntTree left; // left subtree if isLeaf is false
IntTree right; // right subtree if isLeaf is false
}
A valid IntTree
object is either (1) a leaf, where
isLeaf
is true and leafValue
is an
int
, or (2) a composite tree, where isLeaf
is false and both left
and
right
are valid IntTree
objects.
Nothing else is an IntTree
.
Answer the following questions:
IntTree
objects, that every IntTree
has at least one leaf.
t
is an IntTree
,
t.max()
returns the largest leaf value in t
.
IntTree
objects, that your max
method
terminates and returns the maximum leaf value in the tree, when
called from any valid IntTree
.
This question deals with the following labeled (undirected) graph G. The node set of G is {a,b,c,d,e} and it has six labeled edges: (a,b) with label 6, (a,c) with label 1, (a,d) with label 2, (b.d) with label 3, (b,e) with label 3, and (c,d) with label 1.
Answer the following questions:
Last modified 29 March 2013