Introductory Laboratory on Binary Search Trees


Binary Search Trees, Part 2

Summary: This laboratory builds on previous work to provide additional experience using a binary search tree structure.

This lab continues work on program /home/walker/public_html/courses/152.sp01/BST.java, which provides a simple class shell for a binary search tree.

  1. Expand method count to calculate the number of nodes in a tree. In this step, you should change only procedure count, adding additional procedures as needed, but you should not change any other existing procedures. (As before, if something is not broken, do not fix it!)

  2. Expand the stub for method leaves that prints exactly the leaves in a tree. Again, you should not change other existing procedures in working on this problem.

  3. Expand the stub for method delete that removes a specified item from a tree. If the item is not present in the tree, delete should throw a NoSuchElementException. (You also should adjust the main method to catch this exception.)

  4. Print the resulting program, and show the results of your testing.


This document is available on the World Wide Web as

http://www.cs.grinnell.edu/~walker/courses/152.sp01/lab-bst-intro.html

created April 17, 2001
last revised May 14, 2001
Henry Walker (walker@cs.grinnell.edu)