CSE 250 Spring 2004

Programming Project #3

Performance comparison: linear vs. non-linear structures

Introduction

There's trouble at your Hollywood North employer. The rival studio keeps getting all the good actresses and actors. Every time your employer places a call, the prospective star has just gotten off the phone with the competition. Some employees think the competition is using a non-linear data structure in place of a linear data structure to store its data. Your job is to implement an AVL tree based on a binary recursive structure (BRStruct).1 You are only required to define the the insert and find methods for the AVL tree; the delete method is not required. You must present your findings, such as they are, to management in a beautifully written report, devoid of any grammatical or spelling errors.

Required Project Design (50%)

You must implement the AVL tree as a subclass of Container using the BRStruct and visitors subclassing Algorithm. You must fully implement the insert and find operations. You do not need to build any of the other functions of the Container, though doing so can earn you some extra credit points (5% for each extra function, but only if you've completed the basic requirements). You must also overload the << operator for the AVL tree.

You will be graded on the correctness of the AVL code, your adherence to the design (required), and your documentation of the code (comments in the code). You must comment each class and each method within each class as to its purpose and implementation (except for trivial accessors and mutators).

Testing (20%)

You must carry out performance tests (as described in the Report section below. The data from the tests accounts for 20% of your grade for the project.

Report (30%)

You must write a report to employer's top brass. If they like your report they may accept the recommendations you make, even if it means giving up on their much-treasured lists. However, they will not ditch their investment in lists without solid evidence that trees are better.

Your report must include at a minimum the following sections:

Base code

I am providing a base of code for you to work from. Copy the PP3.zip file from /projects/CSE250.2

Hints

Rotations

To implement the AVL tree you need to decide on a represenation for the rotations. It turns out it is relatively straightforward to keep track of rotations while doing insertions. To do an insertion you define a visitor for the BRStruct that (recursively) traverses the tree to the point where the insertion should occur (this will be an empty tree - i.e. a BRStruct whose state is BRSEmptyState).

As you unwind the recursive calls, return a rotation object which is appropriate for the path that you've taken. Remember, as you descend the tree recursively you will go either left or right, depending on where the item to be inserted belongs. Set up your rotation objects so that they all fall under a common Rotation type (abstract class) with common methods specified. You need to have subclasses of all the AVL rotations: two single rotations (left-left and right-right) and two double rotations (left-right and right-left). It turns out it is convenient to have a Null rotation and also left and right rotations.

Set up transitions amongst the rotations; one way to do this is to define a goLeft() and a goRight() method for all Rotations. For example, if r is a Null rotation object, r.goLeft() should return a Left rotation object.

An apply(BRStruct tree) method can be defined for all rotations. When called, the apply method performs the rotation about the supplied tree.

AVL trees

Remember that in order to guarantee O(log n) performance (where n is the size of the tree) for its operations an AVL tree implementation must store the height information for each node and not recompute the height. If the tree is to also store a key with an associated value there are three things in total that each BRStruct node must hold: height, key and value. The height information can be stored as an int, and must not be part of the templatization of the AVL tree.

Two reasonable choices of representation are a triplet (height-key-value) and a pair containing the height and a pair of key and value. I prefer the latter because it is easier to return a pair of key and value for those methods that require it.

Questions?

If you have questions, please ask! If you need clarification or would like more information, please ask! Send e-mail to cse-250-alphonce@cse.buffalo.edu

Submission

Place all and only the files you intend to submit in a directory named PP3. You must name your directory PP3. If you do not you risk having points taken off.

The PP3 directory must include only your source code (declaration and implementation) files as well as your makefile and your runtime report (which must be a postscript or a PDF file). Do NOT submit reports in any other format - they will not be graded.

Your submission must not include object files, executable files or any files whose filenames begin with `#' or end in `~'. You also must not include the SunWS_cache directory and its contents in your submission.

Use the zip utility to create a file named `PP3.zip'. From the directory containing the `PP3' directory, issue the command

    zip -r PP3 PP3
Submit only the resultant `PP3.zip' file.

Use the submit_cse250 command to submit your work.

This project is due on or before 11:59:59 PM on April 10, 2004.


Notes


Carl G. Alphonce
Last modified: Tue Apr 13 14:38:16 EDT 2004