COP4530 Fall 2004: Assignment 5
Due: 15 Nov 2004
Educational objectives:
Statement of work: (i) Implement a self-restructuring BST based on
single rotations, (ii) implement level-order traversal on such trees, and (iii)
use that BST to write a program that will perform searches, and also simple range
searches, as described below.
Deliverables: Turn in a makefile, LOG.txt
file, and all header and cpp files
that are needed to build your project, as described in www.cs.fsu.edu/~asriniva/courses/DS04/HWinstructions.html.
Background: Range searches retrieve data in a
specified range of values. For example, a database may contain data about the
salary and age of people. A range query may ask us to retrieve the records of
all people with age between 20 and 30, having a salary between $100000 and $200000 a year. The dimension of the
problem is, loosely speaking, the number of fields in the record. For example,
in the above the problem, the dimension is two. Many interesting data structures
have been proposed for the above problem. In this homework, we will perform
only one dimensional range search, using a BST.
The
one-dimensional range search is performed as follows. First, find the node v such that the search paths for x takes the left child of v, while the search path for y takes the right child of v. (If such a node does not exist,
then there are no values in open interval (x,y).) Consider the portion of the
search path for x
after encountering v. If the search path takes a left child of a node w, then all the values in the right
subtree of w
are in the desired range. If the search path stops at an internal node, then its right subtree is in the range. Consider the portion of the search path for y after encountering v. If the search path takes a right
child of a node w,
then all the values in the left subtree of w are in the desired range. If the search path stops at an internal node, then its left subtree is in the range. Check all the values on the search paths too, and verify if they are in the range.
Requirements:
-
rBST.h: This file implements a simple generic
self-restructuring BST based on single rotations. Apart from insert, Delete
and search, your class should also
implement a void RangeSearch(T &x, T &y) function which outputs the value of all nodes in the
open interval (x, y). You should
also overload the output operator so that it prints the BST using a level-order traversal, making use of the STL queue class.
-
main.cpp: This is the main program, which will declare an
object of the rBST type. It will then accept a series of commands from the
user, with each command terminated by a newline. It takes an appropriate action on encountering each
command, as described below.
-
quit: causes the program to be terminated
-
insert x: x is an
integer. On reading this command, a
node with key x will be inserted
into the BST. The user will not attempt to insert duplicates.
-
delete x: It causes the node with key x to be deleted from the BST.
-
search x: This outputs Present or Absent,
on a single line, terminated with a newline. This also causes a single-rotation of the node searched for, if it is present.
-
range search x y: This outputs all the keys in the open interval (x
y).
-
print: This prints the BST using a level-order traversal..
-
makefile
Notes:
1.
Your program should not
have any output other than those specified above.
2.
You may use the STL string and queue
classes. Please get my permission before using any other STL feature.
3.
We will provide a sample
input later.
4.
It is a good idea to
create sample test cases to test your program, early in the software development
process.