Laboratory Exercises For Computer Science 195

Modifying Tree Structures

Goals: This laboratory builds on the previous lab to provide experience modifying tree structures.

This lab continues work on program ~walker/c/trees/bst.c that contains a program shell for managing the insertion and print operations for a binary search tree.

  1. Expand the stub for procedure addNameRec that uses a recursive algorithm to insert a name into a tree. As this algorithm is recursive, you will need to identify a simple base case. The recursive case should ask for insertion further downward in the tree. In many respects, the algorithm parallels the recursive function findRec. However, in this case, the root of a tree might change, so the rootPtr parameter must contain the address of the root.

    As in other work, your work should involve changing function addNameRec (adding additional functions if needed), but leaving other existing functions unchanged.

  2. Expand the stub for procedure deleteName that removes a designated name from the tree. The algorithm utilizes both recursion and iteration, as outlined in class. Be sure you understand the algorithm thoroughly before you start to code.

Work to turn in:


This document is available on the World Wide Web as

     http://www.cs.grinnell.edu/~walker/courses/195.fa01/lab.bst-operations.html

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