Laboratory Exercises For Computer Science 195

Introduction to Binary Search Trees

Goals: This laboratory provides some experience using a binary search tree structure.

Orientation: Program ~walker/c/trees/bst.c contains a program shell for operations within a binary search tree. While the shell contains stubs for many operations, it implements three specific functions:

Approaches to Tree Processing: These operations illustrate three basic algorithmic approaches for tree processing.

Details for This Lab: In this lab and the next, you are asked to apply these approaches to fill in the details for other operations that currently are shown as stubs in program bst.c.

  1. Copy program ~walker/c/trees/bst.c to your account, review its structure,study the algorithms used for the completed functions addNameIter, findRec, and print, and run the program a few times to determine how it works.

  2. Expand the stub for function printLeaves that prints only the leaves within the tree. In this process, you should change only function printLeaves. While you may add additional functions as needed, you should not change any other existing functions. (I.e., if something is not broken, do not fix it!)

  3. Expand the stub for function countNodes that counts the number of nodes within the tree.

  4. Expand the stub for function findIter that uses an iterative algorithm to determine if a designated item is located in the tree. You should pattern your iterative algorithm on the approach used in function addNameIter.

  5. Develop a collection of test data to test the new functions thoroughly. What types of cases should be considered? What supporting evidence is necessary to support a claim that the resulting program is correct?

    Use these test data to test your programs thoroughly.

Work to turn in:

This document is available on the World Wide Web as

created September 27, 2001
last revised October 11, 2001
Valid HTML 3.2!
For more information, please contact Henry M. Walker at