CSCI 2720 Data Structures Spring 2004 Programming Project 4 - due *** Saturday April 17 by midnight. *** See the General Project Instructions on the course web site for directions which apply to all projects, including this one. The project has two parts, I and II. I. Extend your templated binary search tree class from Project 2 by adding top-down splay tree implementations of the basic operations, which will be called SplayFind( ), SplayInsert( ), and SplayRemove( ). II. Perform data gathering and timing tests to compare the splay trees and splay operations with the trees and operations from Project 2. Also build a large linear tree and see how many splay operations are needed to achieve a reasonably balanced tree. Part I. Templated Binary Search Tree class with Splay Operations Specify and implement a binary search tree class BST just as for Project 2 except for the addition of the three splay operations and the standardizations noted below. As in Project 2, Dtype is to be the data type for the tree and Ctype contains a static function lt which defines the tree's inorder ordering. However for Project 4 the assumptions for lt are less strict, as follows: given inputs x, and y of type Dtype, the function Ctype::lt(x,y) returns an integer < 0 (not necessarily -1) if x should come before y in the ordering, an integer > 0 (not necessarily 1) if y should come before x in the ordering, and 0 if x and y are equal. The other standardization is that Stats( ) should return -1 as the ordered height of an empty tree. Before going on to part II you should test your BST< , > class using SplayFind( ), SplayInsert( ), and SplayRemove( ), as well as all of the functions required for Project 2. Make sure it works for int data and the default comparison, and on C style strings with the strcmp for the comparison function (wrapped to make it accessible, but otherwize unchanged). For instance, starting with an empty tree of type BST the splay operations should give the following results: insert: 10 20 30 40 50 60 output: 1 1 1 1 1 1 pre-order: 60 50 40 30 20 10 find: 18 output: 0 pre-order: 10 50 30 20 40 60 remove: 40 output: 1 pre-order: 30 10 20 50 60 REQUIRED INTERFACE AND FEATURES Be sure to name your class BST and provide public member functions named SplayFind( ), SplayInsert( ), SplayRemove( ) in addition to those required for Project 2. These new functions must each take a const Dtype& input and return an int. Each should return 1 if the operation was successful, and 0 if not (i. e., return 0 if you try to insert a key already present in the tree, or find or delete a key which is not present). The implementations must carry out top-down splay operations as described in the paper by Sleator and Tarjan (class handout). The functions SplayFind( ), SplayInsert( ), and SplayRemove( ) must be carried out as described in Section 7.3 of the Lewis and Denenberg text except that each splay operation will be top-down instead of bottom-up. Your specification should be in a file called splay.h and your implementation should be in splay.cc. Part II. Tree Shape and Timing Experiments (a) Repeat your experiments from Project 2 with neutral, left-biased and right-biased search trees but using the functions SplayFind( ), SplayInsert( ), and SplayRemove( ) instead of Find( ), Insert( ) and Remove( ). In your discussion, compare the results from Projects 2 and 4. Explain your findings. (b) SplayInsert the numbers 0 ... 9999 IN ORDER (0 first, etc.) into an empty BST tree and run TreeStats on it. Then execute SplayFind(0), SplayFind(1), SplayFind(2), ... SplayFind(12), running TreeStats after each find. In your discussion point out what is happening to the internal path length and explain why it is happening. (c) Devise your own timing experiments to compare the speed of the three splay operations with the speed of the original versions from Project 2, using random and biased trees. In your discussion give a summary of how they compare for speed on the different types of trees. REQUIRED INTERFACE AND FEATURES The code for the tree shape experiments should be in a file named "splaytree.cc", or if you find it more convenient in separate files for the different types of bias and for the linear tree experiment. The code for the timing runs should be in a file named "splaytime.cc". The data you obtain should be tabulated in proj4_data, and you should then discuss their significance in a separate file, proj4_discussion.