CS 314 - Specification 9 - Binary Search Trees

Programming Assignment 9: Individual Assignment. You must complete this assignment on your own. You are encouraged to use code presented in the binary search tree lectures. You may not acquire from any source (e.g.  another student,  an internet site, Large Language Model or Generative AI such as chatGPT or COpilot) 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. You may get help from the instructional staff. You may discuss general ideas and approaches with other students but you may not develop code together. Review the class policy on collaboration from the syllabus.

The purposes of this assignment are:

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

Requirements:

1. Implement a binary search tree class. Make the data structure generic using Java's generics and parameterized data types.

2. You are free to use the code we developed together in lecture, just put a comment stating the code came from lecture. I expect you to use the simple insertion algorithm we developed in class.

3. Like assignment 1, you may not look up algorithms, in this case for balanced binary search trees. You may not use the TreeSet or TreeMap classes from the Java standard library when implementing your Binary Search Tree. You will use the Java TreeSet class in some experiments.

4. Use of Java's lambdas and streams is disallowed per the program hygiene guide. Any solutions that use Java's lambdas (the arrow operator, ->)  and / or streams shall be assigned a score of 0.

5. The assignment guidelines require that "If you learn a technique, approach, or algorithm from a third party source (you didn't know it before hand and we didn't cover in in CS314 lecture, materials, etc.), you must cite that source as a comment in your code." Item number 15 in the assignment requirements. If you learn a  technique, approach, or algorithm from a third party source and do not cite that source the assignment score shall be 0.

If you have questions regarding what constitutes the use of Java's lambdas and / or streams OR whether to cite a source make a post to the class discussion group on Ed.


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. Delete the original tests. Add at least 2 more tests per method and your experiment code. 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.
All Files All files in one zip. Provided by me.

BinarySearchTree.java is class that implements a binary search tree as discussed in lecture. Use the naive insertion and removal algorithms demonstrated in lecture. You may use the code we wrote in lecture. I have specified the methods for the class. Complete the implementation under the constraints of the general requirements. There is a method named printTree which prints out a representation of the current tree. It is a horizontal representation. This method is already done and can be useful in debugging. Read the documentation for 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.

BSTTester.java contains several tests for the BinarySearchTree class. After you are sure the original tests are correct and that your class passes them, delete the original tests. 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 data tables and answers in a comment at the top of your BSTTester class.

Note: The get(int kth), getAllLessThan(E val), and getAllGreaterThan(E val) methods shall be as efficient as possible in terms of time and space. Meaning make the T(N) as small as possible. You could use the getAll method but you will very likely fail some stress tests if you take that approach. You must stop your search or processing as soon as you can. Don't do any extra work. All 3 of these methods can be solved with recursive backtracking. (No loops for choices, due to limited number of choices, but recursive backtracking nonetheless.)


Checklist: Did you remember to:

  1. review and follow the general assignment requirements?
  2. work on the assignment by yourself?
  3. fill in the header in your BSTTester.java and BinarySearchTree.java files?
  4. ensure your version of BinarySearchTree passes the tests in BSTTester.java and add your own tests?
  5. ensure your program does not suffer a compile error or runtime error?
  6. run the experiments described in questions.txt and answer the questions in questions.txt? place your answers in a comment at the top of your BSTTester.java file.?
  7. turn your Java source code files (BinarySearchTree.java and BSTTester.java) to the proper GradeScope assignment (#9) before 11 pm, Thursday, November 13?