Docsity

Binary Search Trees and Recursion Lab in Computer Science II, Lab Reports of Data Structures and Algorithms

Toggle sidebar
bg1
Computer Science II — CSci 1200
Lab 9
Binary Search Trees and Recursion
Introduction
This lab explores binary search trees and their implementation in the cs2set
class, along with the use of recursive functions to manipulate binary search
trees. Once you have a basic understanding of trees, the actual code that you
have to write for the lab is quite short. Review the notes from Lectures 16
and 17 prior to starting.
Download the files:
http://www.cs.rpi.edu/academics/courses/spring07/cs2/lab09/cs2set.h
http://www.cs.rpi.edu/academics/courses/spring07/cs2/lab09/test_cs2set.cpp
Then, turn off all network connections.
Examine the code in cs2set.h and testset.cpp. The former contains
the implementation discussed in Lectures 16 and 17, including the functions
implemented in lecture as exercises. The latter contains code for testing
the implementation. Some of this has been commented out because all the
functions have not yet been implemented.
Checkpoints
1. The implementation of find provided in cs2set.h is recursive. Im-
plement and test a non-recursive replacement for this function.
2. The implementation of the copy constructor and the assignment op-
erator is not yet complete because each depends on a private member
function called copy_tree, the body of which has not yet been written.
Write copy_tree and then test to see if it works by “uncommenting”
the appropriate code from the main function.

Partial preview of the text

Download Binary Search Trees and Recursion Lab in Computer Science II and more Lab Reports Data Structures and Algorithms in PDF only on Docsity!

Computer Science II — CSci 1200

Lab 9

Binary Search Trees and Recursion

Introduction

This lab explores binary search trees and their implementation in the cs2set class, along with the use of recursive functions to manipulate binary search trees. Once you have a basic understanding of trees, the actual code that you have to write for the lab is quite short. Review the notes from Lectures 16 and 17 prior to starting. Download the files:

http://www.cs.rpi.edu/academics/courses/spring07/cs2/lab09/cs2set.h http://www.cs.rpi.edu/academics/courses/spring07/cs2/lab09/test_cs2set.cpp

Then, turn off all network connections. Examine the code in cs2set.h and testset.cpp. The former contains the implementation discussed in Lectures 16 and 17, including the functions implemented in lecture as exercises. The latter contains code for testing the implementation. Some of this has been commented out because all the functions have not yet been implemented.

Checkpoints

  1. The implementation of find provided in cs2set.h is recursive. Im- plement and test a non-recursive replacement for this function.
  2. The implementation of the copy constructor and the assignment op- erator is not yet complete because each depends on a private member function called copy_tree, the body of which has not yet been written. Write copy_tree and then test to see if it works by “uncommenting” the appropriate code from the main function.