Assignment 4
Due: 6 Nov 2014
Educational objectives:
- Primary objectives: Implement a simple self-restructuring binary search tree.
- Secondary objectives: Implement and use templates, develop test cases to test the correctness of your software, empirically compare the performance of different data structures.
Statement of work: Implement a generic self-restructuring binary search tree class, using a self-restructuring scheme specified below.
Deliverables:
- Turn in a
makefile
and all header (*.h) and cpp (*.cpp) files that are needed to build your software, as described in www.cs.fsu.edu/~asriniva/courses/DS14/HWinstructions.html. Turn in your development log too, which should be a plain ASCII text file calledLOG.txt
in your project directory.Requirements:
- Create a subdirectory called
proj4
.- You will need to have a
makefile
in this directory. In addition, all the header and cpp files needed to build your software must be present here, as well as theLOG.txt
file.- You should create the following additional files.
- MRBST.h: This should implement a generic
MRBST
class. This class is a self-restructuring binary search tree. It restructures by rotating a node with its right child, if the node is found by thesearch
operation, and if the right child exists. (We are assuming that if a node is found, then it is less likely to be searched for in the near future.) You should implement at least the following features: (i)void push(const T &)
, (ii)bool search(const T &)
, (iii)void PrintPreorder()
, (iv) a default constructor without arguments, and (v) a destructor. Thepush
function inserts a node into the tree. Thesearch
function returnstrue
if and only if its argument is present in the tree, and also causes a restructuring operation to be performed. ThePrintPreorder
function prints the values stored in each node, using a pre-order traversal.- test.cpp: This is a code that you write to check whether your tree works correctly. Note that we will not provide a sample executable for this assignment. You should create suitable test cases and test your code thoroughly.
- compare.cpp: This program will be compiled to create an executable called
compare-containers
, and the executable will be run as follows.This code should store all the words in the dictionary available in ~cop4530/fall14/solutions/proj4/words on linprog into three different containers: (i) MRBST, (ii) STL
./compare-containers Filename
, whereFilename
is the name of a file containing words separated by whitespaces. Each word contains a string of lower case letters.list
, and (iii) STLset
. (We will copy this file to the current working directory before running your program; you should do the same.)It will then check if each word inFilename
is present in the standard dictionary using each of the three containers. It will also determine the time taken by each container to check each word and output each result, mentioning the word, container and time taken. For example:
aim, MRBST, 0.001 seconds
aim, list, 0.01 seconds
aim, set, 0.001 seconds
zebra, MRBST, 0.01 seconds
zebra, list, 0.02 seconds
zebra, set, 0.01 seconds
aim, MRBST, 0.002 seconds
aim, list, 0.01 seconds
aim, set, 0.001 seconds
- result.txt: This is an ASCII text file. It should first describe how you tested your
MRBST
code. It should then discuss the relative performance of MRBST against that of the STLlist
andset
. For example, under what situation is one data structure better than the other in terms of search time. Justify your conclusions with timing results. If the MRBST had rotated searched words one level up, then would its performance have been better for this application?Note:
- We will test your
MRBST
class with code that is different from yourtest.cpp
. So it is important for this class to be generic and exactly as specified.- Your code should be efficient and your makefile should use good optmization flags.
Last modified: 28 Oct 2014