HW17: Spell Checker

25 points; due Fri 5/30 @ 11am.

Goals

To write and use a Set implementation.

Setup and Requirements

Download Set.java.

This is optionally a partner assignment.

Your Tasks

  1. Write a BST-based Set implementation called BstSetImplementation. Include a main method to test its functionality. In particular, make sure that you extensively test the edge cases of the union() and intersect() methods.

    Note that the Set interface defines this ADT for storing any kind of object. However, a BST-based implementation will only work for types that have an ordering on them; that is, those that implement Comparable. Make sure your class's signature reflects this fact.

    As with other iterable ADTs, I expect you to write a full implementation of toArray(). You are not required to write a real implementation of iterator(); this method may instead just throw an UnsupportedOperationException.

  2. Use your Set to implement a spell-check program.

    Write a separate class, SpellCheck, whose main method takes two filenames from the command line: first the name of a text file to be checked, and second the name of a “dictionary” file that contains correct spellings of a bunch of words, one word per line. You may wish to recycle source material from the “Timing Collections” assignment. It is acceptable to treat all punctuation as spaces — that is, don't include them in any “words” — and to ignore capitalization. (So the string “Don't”, for example, would be treated as two words: “don” and “t”.)

    Print out all words in the source file that do not appear in the dictionary file. Make this a polished program; it should gracefully handle errors.

    Note that your set's underlying tree will be extremely unbalanced if you add the dictionary words to it in alphabetical order. Do some extra work in your program to make it likely that your tree will be moderately well-balanced. You may assume sorted input if you'd like, but you may not assume unsorted input — that is, it should behave well with sorted input. The design of your balancing technique is up to you, and you're welcome to put this functionality in a Set constructor rather than in SpellCheck. If your balancing technique requires other ADTs, you're welcome to use my “mystery” implementations or your own.

Submission and Grading

Zip up your BstSetImplementation.java and SpellCheck.java (and any additional ADT or implementation files needed for your spell-checker) into hw17.zip and submit it on Moodle.