Q1: 15 points Q2: 30+10 points Q3: 35 points Q4: 15 points Q5: 20 points Total: 100+10 points
For example, S(1) = -1, S(2) = -1 + 3 = 2, and S(3) = -1 + 3 - 5 = -3.
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.
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.
maxUpTo
for the IntTree class that takes an
int argument cap and returns an
int. If there is any leaf value in the tree
t that is less than or equal to cap,
t.maxUpTo(cap) should return the largest such
value. If there is no such value, t.maxUpTo(cap)
should return cap + 1.
Last modified 21 December 2010