CIS 22 - Data Structures


Spring 2005

Assignment #6 - Binary Search Trees

Due: May 16, 2005


Overview

This assignment consists of implementing several features of binary search trees :

Many opportunities for Extra Credit are given below.

NOTE: You must test the Binary Search Tree class fully Choose your test cases carefully to test all cases. If you do not fully test your class, it will be assumed that it doesn't work properly. Annotate the output - draw pictures (by hand) of the trees - to illustrate the test cases.

You must implement the remove function of the BSTree class. You may either actually remove the item from the tree, or you may flag the item as "deleted". Note that if you choose to use a flag, you may need to modify the BinTree and TNode classes as well.

Testing

As usual, design test data that will test your code thoroughly. For example, make sure that you test remove thoroughly - remove an item that is in a leaf, remove an item that is in a node with one child, remove an item that is in a node with two children, remove the root, remove from a tree with only one node, etc.

Extra Credit

You may do any or all of the options below for extra credit. Be sure to indicate on your submission which extra credit items you did.

  1. Implement and test a level-order traversal using queues.

  2. Implement and test a non-recursive traversal using the father pointers.

  3. Implement the tree using right inorder threads. (You will have to add a boolean field to the tree node, isthread, to be able to identify whether a right pointer field is a true child or is a thread.) At the end of the program, print out the trees using the recursive traversal, and then also print them out non-recursively using the threads. You can read more about threads and the nonrecursive traversal in your textbook.

  4. Implement a binary tree iterator. At the end of the program, after printing out the trees recursively, also print it them out non-recursively using the iterator. Code for a binary tree iterator is on this web site.

If you choose to do extra credit, please note what you have done on the cover page of what you hand in, as well as in your comments.