Lab 3: BST

Due Date and Submission Requirements


The goal of this lab is:


Directions

In this lab, you will build some methods for a simple binary search tree that stores integers. You will continue using the code that we have been building in class (Jan 30 + Feb 4), however I'd recommend downloading a fresh set of files below.

This is how the BST looks after a series of inserting nodes:



You should not modify the BSTDemo class or the Node class. You are allowed to modify the BST class and add any additional methods or instance fields (you probably will need add some things to the BST class). You will fill in the bodies for the following methods:

1. public void inOrder(Node n) . This method prints out the BST using inOrder traversal. Make sure that it matches the sample output below. Look at the slides from Tuesday 2/4 if you are stuck.

2. public void breadthFirst() . This method prints out the BST using breadth-first traversal. We wrote breadth-first traversal for a generic tree in class, but you will now need to modify that code so that it works with a binary search tree.

3. public int getMin(). This method will return the minimum value in the BST. If there are no values in the BST, return -1. You are NOT allowed to use breadth first, depth first, in order, post order, or pre order traversal

4. public int getMax(). This method will return the maximum value in the BST. If there are no values in the BST, return -1. You are NOT allowed to use breadth first, depth first, in order, post order, or pre order traversal

5. public Node find(int value). This method will return the Node whose value equals the input parameter value, if in fact that input parameter value exists in the BST. If the BST does not contain the input parameter value, return null. You are NOT allowed to exhaustively search the whole tree for the input parameter value. It must go from the root to the input parameter value via the shortest path, just as our insert() method in class did. You are NOT allowed to use breadth first, depth first, in order, post order, or pre order traversal

Required Output

When you run your program, it should look exactly like this output .

Starting Code

Grading (10 points)

NOTE: If your code does not compile, correctness cannot be verified and you won’t receive any points for your code. Turn in code that compiles!