Back to the Lab Index

Lab 9 - BST Mastery Exam Practice
Due: Wednesday, November 8th at 11:59PM

The Assignment

Your assignment for this week is to answer 3 of the mastery exam questions for the BST section of the mastery exam. The three questions you will solve are: Below is the description of these three methods.

boolean isPerfect()

Returns true (a boolean value) if, and only if, all leaves of the tree are at the same level (are the same distance from the root) and the tree has the maximum number of nodes for its depth (each node has exactly 0 or two children), and false otherwise.

int balancedFactorOfNode(Comparable value)

This method returns balanced factor of a given node with value. If the node does not exist, return -1. Balanced Factor is defined as the absolute value of the difference in heights between left and right subtrees of the node.

void printLeavesAtLevel(int level)

Prints to the console a list of all items organized at the specified level of the tree.

Testing

You will also have to write your own tester for this lab. Write a main method that will create certain BST's (hopefully some with edge cases contained in them) and will call on these methods to test them throughly. Below are the given Java files you need to get started.

Files