Name: _____________________ Netid: _________________ Name: _____________________ Netid: _________________ Name: _____________________ Netid: _________________The tree below is a binary search tree.
|
|
|
printQ
below prints one line for every node in a tree. The first
value printed when called with the tree above is
the string macaque. What is the complete output?
printS
below prints one line for every node in a tree. The first
value printed when called with the tree above is
the string macaque. What is the complete output?
The complexity of method copyCount
below is
not O(n)
for an n-node tree. Suppose for example that every time
count
is called with a specific node as a parameter the
node gets one cent deposited in it. The root only gets one
cent deposited in it --- why? How many cents get deposited in
each leaf shown? Why? If the total cost of the method
copyCount
includes these pennies/cents, can you provide
a cost of the entire complexity using big-Oh? Assume a tree is perfectly
balanced in coming up with an answer, e.g., there are two
nodes below the root, four below that, eight below that, etc.,
with each level containing a power of two. For an N-node tree,
roughly half the nodes are in the last level, how many pennies
are in each of these leaf nodes? Given this as a starting point,
what is the big-Oh complexity of the method copyCount
below?
fastCopy
should run in
O(n) time for an
n-node tree and should create a counted-copy as described
previously. Justify that your solution is
O(n) by writing a recurrence
for it.