The final exam is Thursday, December 14 2-5pm in the usual classroom.
There will be a review session in Jacobs B134 on Tuesday, December 12 at 6:30 PM.
You may bring up to two 8.5 by 11 sheets of paper to the exam with anything you want on both sides of the sheets.
Below is a study guide and some practice problems to help you prepare for the final exam. In addition to using this guide, we strongly recommend carefully reviewing the class homework assignments and your notes. The exam will be comprehensive.
You have been hired by Millisoft. Your boss, Gill Bates, drops by your spacious cubicle sipping a refreshing and stimulating Jolt Cola ("All the sugar, and twice the caffeine!"). Gill begins by reminding you that a decider is a program that takes an input and eventually halts and accepts (says "yes" to its inputs) or rejects (says "no" to its input). For example, a decider for the prime numbers would take a number (perhaps encoded in binary) as input and would eventually halt saying "yes" (it's prime) or "no" (it's not prime).
class Node
{
public int key;
public Object data;
public Object children[];
public int num_children;
public final int MAXCHILDREN = 100;
Node(int key, Object data, Object children[])
{
this.key = key;
this.data = data;
children = new Object[MAXCHILDREN];
num_children = 0;
}
}
In this node class, key is a unique ID for the node, data is a reference to some Object and children is the array of the node's children.
Consider a tree made of such of nodes in which the tree has no particular organization. That is, the tree is not sorted in any way. Write a method that takes as input the root of such a tree and reorganizes the tree so that every node has at most two children and for each node, its "left" subtree contains nodes with strictly smaller keys and its "right" subtree contains nodes with strictly larger keys. In addition, the tree must have height O(log n) where n is the number of nodes.