CS 307Assignment, Binary Search Trees

Programming Assignment 9: This is an individual assignment. You must complete this assignment on your own. You may not discuss their work with anyone except the instructor and other members of the instructional staff (TA, section leader, or lab proctor). You may not acquire, from any source (e.g., another student or an internet site), a partial or complete solution to a problem or project that has been assigned. You may not show another student your solution to an assignment. You may not have another person (current student, former student, tutor, friend, anyone) “walk you through” how to solve an assignment. Review the class policy on collaboration from the syllabus.

Placed online: Friday, August 6
20 points, ~2% of total grade
Due: no later than 11 pm, Friday, August 13. You may not use any slip days on assignment 9.


Description:  The purposes of this assignment are:

  1. implement a binary search tree
  2. observe the behavior of binary search trees when adding random data and data already in sorted order

In this assignment you will implement a binary search tree class. You will make this data structure generic using Java's generics and parameterized data types syntax. You are free to use the code we have developed together in lecture, just put a comment stating the code came from lecture. You may not use the TreeSet or TreeMap classes from the Java standard library when implementing your Binary Search Tree. You must use the TreeSet class to answer some of the questions on the assignment.

When finished turn in your BinarySearchTree.java and BSTTester.java files (BSTTester will contain your answers to the questions and experiments in a comment) using the turnin program. No jar file this time.

Provided Files:

  File Responsibility
Source Code Stopwatch.java. Used to record times of experiments in questions.java. Provided by me. Do not alter.
Implementation BinarySearchTree.java An implementation of a binary search tree. Provided by you and me. Mostly you.
Documentation Javadoc for the BinarySearchTree class. Provided by me.
Test code BSTTester.java contains several tests for the BinarySearchTree class. You must ensure the tests are correct and your class must pass these tests. Add at least 2 more tests per method. Provided by you and me.
Reflection questions.txt Place your answers to these questions in a comment at the top of your BSTTester.java file. Provided by me.

BinarySearchTree.java is a binary search tree class. I have specified the methods for the class. Complete the implementation under the constraints of the general requirements. You may use code from the text and in class as long as your cite your source. You may add more instance variables if you want and there is a valid reason to do so. There is a method named printTree which prints out a representation of the current tree. It is a horizontal representation. Read the documentation for other details.

BinarySearchTree.BSTNode. This is a class nested inside the BinarySearchTree class. Use instances of this class to store the data in the binary search tree. This is very similar to the BSTNode class presented in class, but now we are nesting it inside the BinarySearchTree class.

BSTTester.java contains several tests for the BinarySearchTree class. Some of these tests may be incorrect. You must determine which, if any of the tests are incorrect, and fix them. I encourage you to use the class listserv to determine if any of the tests are incorrect and how to fix them. Add at least 2 tests per method in the BinarySearchTree class.

questions.txt contains a number of questions to and experiments regarding your completed BinarySearchTree class. Place your answers in a comment at the bottom of your BSTTester class.


Checklist:


Tips:

  Back to the CS 307 homepage.