(Latest Revision: 05/06/2001)
Working With Trees: Extending the Binary Search Tree Class
THE ASSIGNMENT:
Your assignment is to extend the Binary Search Tree ADT by
adding the following operations:
Name Type Purpose
PrintTree void function Print a representation of a
binary search tree to the standard
output.
PrintLevels void function Print representations of the
nodes of a binary search tree
level-by-level to the standard
output.
Height int function Determine the height of a
binary search tree.
IntNodeCount int function Determine the number of internal
nodes in a binary search tree.
In other words, you must make additions to BST2.h and BST2.cpp so
that bstClass makes the new operations available.
PrintTree:
The function PrintTree must have output like this:
Yucca
Willow
Walnut
Tamarack
Spruce
Poplar
Oak
Maple
Larch
Juniper
Hawthorne
Ginkgo
Fir
Dogwood
Beech
Almond
PrintLevels:
The function PrintLevels must have output like this:
Maple
Ginkgo Tamarack
Dogwood Juniper Poplar Willow
Beech Fir Hawthorne Larch Oak Spruce Walnut Yucca
Almond
SPECIFICATIONS:
The first part of your assignment is to write the specifications
of each operation in the following format:
Operation (parameter list)
Function:
Inputs:
Preconditions:
Outputs:
Postconditions:
Here is an example that that shows how the format looks when
applied to a void function called FindNode. Your operations will
probably all have simpler postconditions than the ones for
FindNode.
void FindNode
( keyType keyValue ,
ptrType& nodePtr,
ptrType& parentPtr
);
Function:
- Find the node that contains keyValue;
Inputs:
- keyValue -- the key value of the tree node to be
sought.
Preconditions:
Outputs:
- nodePtr -- a pointer for the node sought, and parentPtr
- parentPtr -- a pointer for the parent of the node sought
Postconditions:
- If the search succeeds and the node sought is not the root node:
- then nodePtr points to the node sought, and
parentPtr points to the parent of the node
sought.
- If the search succeeds and the node sought is the root
node:
- then nodePtr points to the node sought, and
parentPtr is NULL.
- If the search does not succeed and the tree is not
empty:
- then nodePtr is NULL and parentPtr points to the
tree node that would be the parent of the node
sought, if that node were in the tree.
- If the tree is empty:
- then nodePtr is NULL and parentPtr is NULL.
IMPLEMENTATIONS:
Once you have specified the operations, you must implement them.
For PrintTree, Height, and IntNodeCount you should find a
recursive solution. For PrintLevels, I recommend a solution that
employs a queue as an auxiliary data structure.
Let's discuss in class the solutions to the problems encountered
when we try to implement these operations.
TESTING THE OPERATIONS:
You must test each new operation thoroughly to make sure it is
correct. To do that you must decide on a set of test inputs for
each function. The set of test inputs has to give good data and
code coverage. You must write a test plan telling in
detail what test inputs you are going to use for each operation.
Your grade is determined in part by the completeness of your test
plan. (See the file test_Plan_Ideas in this directory)
Create a batch test driver program driver.cpp that executes
your test cases. The driver must write all output to standard
output (the screen).
It's important that the output of driver.cpp be
self-explanatory. Just from looking at the screen the user
must be able to tell what the inputs to each test are, what the
test does, and what the outcome is. For example use "before"
and "after" labels, statements, and calls to PrintTree to
accomplish this.
Your test driver is allowed to call any of the public operations
that are declared in the files BST2.h or Data.h. Of course,
your driver may also call any of the operations that you add by
making changes to bstClass.
I have included in this directory the file driver_Ideas,
which contains some additional advice about writing the driver
and a small sample of the kind of code your driver needs to have.
The driver code found there is not a complete driver.
WHAT TO TURN IN:
- Before midnight on the first due date, turn in:
- specifications for all the new operations,
- your test plan, and
- the code for at least 1 of the 4 new operations.
You must
shar all the materials above into a single archive
file and send them via e-mail with subject line:
"CS2500,prog5.plans".
- Before midnight on the second due date, turn in:
- your completed copies of BST2.h, BST2.cpp,
- copies of Data.h and Data.cpp (unchanged),
- your driver.cpp file, and
- a script showing the outcome of an execution.
You must
shar all the materials above into a single archive
file and send them via e-mail with subject line:
"CS2500,prog5.fin".
Note that there are no spaces in the subject lines given. It
is important that you do not insert any spaces. My e-mail
address is:
john@ishi.csustan.edu.
DUE DATES:
For the due dates, see
the class schedule.