Goals: This laboratory provides some experience using a binary search tree structure.
~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:
addNameIterinserts a name into the tree,
findRecsearches a tree for a specified name, and
Approaches to Tree Processing: These operations illustrate three basic algorithmic approaches for tree processing.
addNameIteruses iteration to work downward node-by-node through a tree. A variable
treePtrstarts at the root of the tree and progresses left or right down the tree from one level to the next, until it comes to a place where a new node may be added.
findRecuses recursion to work downward through a tree. Following usual patterns of recursion, base cases handle the simplest cases (in this case, a null tree or a tree where an item is found), and the recursive step allows movement downward from one level to the next.
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
~walker/c/trees/bst.cto your account, review its structure,study the algorithms used for the completed functions
addNameIter, findRec, and
printLeavesthat 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!)
countNodesthat counts the number of nodes within the tree.
findIterthat 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
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
|For more information, please contact Henry M. Walker at firstname.lastname@example.org.|