Binary Search Tree Lab

CPE 103 

Before you write any code, read the directions and write a test plan.  Draw the tree you will create, the data to be input (in order), and show the exact program output you expect.

Implement the test plan you wrote as JUnit test to demonstrate that all six methods perform correctly.   Compile your test and run it.  It should compile without error, and when executed it should report that the tests fail.  (Your test of the print method won't have any asserts; it will rely on human inspection of the output to verify correctness.)

We will be enhancing Weiss's BinarySearchTree implementation.
Download:

In the class header comment for BinarySearchTree include separate @author tags for each student.

Implement the following six methods in your class.  The search() and traverse() methods must be implemented recursively. search() must not call find().

   /** See if the tree contains a given item.
    * @param target the item to search for
    * @return true if the item is in the tree
    */
   public boolean contains(AnyType target)

    /** Recursively search the tree for the target */
   private boolean search(BinaryNode<AnyType> curr, AnyType target)

   /** Show an ordered list of the items in the tree,
    * one item per line.     */
   public void list()
        
   /** Recursive in-order traversal of the tree, printing each node */
   private void traverseInOrder(BinaryNode<AnyType> curr)

   /** Print a formatted display of the tree.  */
   public void print()

   /** Recursive pre-order traversal of the tree, printing each node
    * indented an amount corresponding to its level in the tree.
    */
   private void traversePreOrder(BinaryNode<AnyType> curr, int indent)
        

The formatted display uses indenting to show nodes on the same level at a consistent level of indentation, and periods where no child exists.
For example, the tree in this diagram  would print like this:

   E
      D
         .
         .
      N
         K
            F
               .
               H
                  .
                  .
            L
               .
               .
         S
            .
            W
               .
               .


Remember that you must use recursion (not iteration) to solve this problem.

Submit a printout of the BinarySearchTree class, your JUnit tests, and output from running your tests..



The tests your wrote earlier should now be passing. Demonstrate your completed tests to the instructor.

Be sure each student has a copy of the source code, as it will be needed for the next lab.

There is nothing to submit for this lab.  We will be enhancing your work in the next lab, and submitting it when it is complete.