EECS 360 - Machine Problem 3

Binary Search Trees and Splay Trees

Due: 11:59 pm on Thursday 10/12/2000

For this assignment you must work alone.

This assignment will have you maintaining two trees. One is a regular binary search tree. The other is a Splay tree. We will perform the same operations on both trees to see how the Splay tree is an improvement over the regular binary search tree. We will implement the following operations:

a <el1>, <el2>, <el3>, ... <elN>
Add all N elements to the trees. An error message should be printed if an element that is already in the set is attempted to be added. The list of elements will always have at one integer value. Except for the last integer value, the integer values will be followed immediately by a comma. The elements are to be added to the trees in the order they are given.

c
Clear all elements from both trees. You must properly deallocate all dynamic memory used by the trees. Print some message stating that both trees are empty.

f <el1>, <el2>, <el3>, ... <elN>
Find all N elements in the tree. For each element, print a message whether the element was found or not found in the trees. This operation is mainly used to show the every changing form of the Splay tree. Since the trees must have the same elements in them, this operation need only be performed on the Splay tree. Except for the last integer value, the integer values of the elements will be followed immediately by a comma. The elements are to be found in the trees in the order they are given.

r <el1>, <el2>, <el3>, ... <elN>
Remove all N elements from the trees. An error message should be printed if an element that is not in the set is attempted to be removed. The list of elements will always have at one integer value. Except for the last integer value, the integer values will be followed immediately by a comma. When removing an element from the tree, you must properly deallocate any dynamic memory that is no longer needed. The elements are to be removed from the trees in the order they are given. Note: you may NOT implement a "lazy deletion" scheme for your trees.

p
Print both trees showing the binary tree structure. Clearly state which tree is which when being printed.

h
Determine and print the maximum height and average height of both trees.
     average height = (height (el1) + height (el2) + ... 
                        + height (elN))/number of elements

q
Quit the program. Print an appropriate good-bye message upon completion of your program.

The input for the program will be given through standard input. Each line of input will have one and only one operation. Each operation will fit on one line of input. You may assume that each line is no more than 100 characters long. The first non-white space character will be the character for the operation. If an unknown character is given, print out an error message such as Operation X is not known and ignore the rest of the the input line. Typical white space characters are the space an tab characters.

Since this program is to be interactive, your program is to prompt the user for each command.

General Comments

Your program must properly implement the algorithms that are given in class and in the Weiss text in chapter 4. Failure to do this will result in a lower score for this project. Note: the code from chapter 12 is for "top-down splay trees" which is NOT what we are covering in lecture.

Your program must be written in good programming style. This includes (but is not limited to) meaningful identifier names, a file header at the beginning of each source code file, a function header at the beginning of the function, proper use of blank lines and indentation to aide in the reading of your code, explanatory "value-added" in-line comments, etc.

The work you turn in must be 100% done by your own own. You are not allowed to share code with any other students (inside this class or not). You may discuss the project with other students; however, you may not show any code you write to another student nor may you look at any other student's written code.

You are to submit this project using the EECS Department's UNIX machine's turnin command. The project name for this assignment is mp3. Be sure to submit all source code and header files and makefile. Failure to turnin all required pieces will result in a lower grade for the assignment. The turnin command for this assignment is:

     turnin -c eecs360a -p mp3 <file list>
where <file list> is the names of all files that you will submit for this program. You can use the turnin command multiple times; however, ever time you must submit all files needed for the program. To see which files you have submitted to turnin use the -v option with the turnin command as follows:
     turnin -c eecs360a -p mp3 -v