Lab 8: A Binary Search Tree Class

Due Date: midnight Wednesday, November 13


Background:

Lab 8 will allow you to practice recursive Java routines as well as developing a class from scratch. You will re-use (and extend) the Word class from Lab 4 as you implement a binary search tree of words.


What You'll Need

Download the lab8.zip file from the 15-111 course web site. Unzip the file and you should see the following:


Assignment

For this assignment, we're going to build a Binary Search Tree of words (we'll turn it into a REAL TextTwist helper for the next assignment). You'll want to model your Binary Search Tree class on the linked list class we developed over the last few weeks and on the code from lecture.

You will be implementing a WordTree class that uses BinaryNode to implement a Binary Search Tree of Words. Your WordTree class must implement the following public methods (its interface):

You will need to modify the Word class to implement the Comparable interface (since we have to compare Words). This means you must implement the compareTo(Object o) method in your Word class and add implements Comparable to the class declaration. The compareTo method is invoked by a Comparable object, and takes another object as a parameter and returns an int. When called as (Comparable) x.compareTo(y), the method returns a negative integer if x < y, 0 if they're equal, and a positive integer if x > y. FYI, Strings are comparable.

You should write this code incrementally and test it on words.txt before trying the larger file. Note, for this assignment, we're not filtering words to be inserted. Every word in the file, regardless of length, should be inserted in your WordTree.

A discussion of the design and demo of the solution will take place in Thursday's lecture.


Handing in your Solution

Your solution should be in the form of a .zip file. When we grade your solution we will unzip the folder and execute the files using our own driver.

Use the Intro Programming dropoff form to submit your zip file.