CSCI 136 - Fall 2018
Data Structures & Advanced Programming
Home |
Lectures |
Labs |
Handouts |
Links |
CS@Williams
Lab 9 Tips and Tricks
This document should help you to organize your design and
plan your implementation for the Super Lexicon Lab.
Be sure to read the lab handout
thoroughly!
Super Lexicon Classes
-
Main.java: driver program. No need to modify!
-
Lexicon.java: Interface. No need to modify!
-
LexiconTrie.java: implements interface. You will make changes here.
-
LexiconNode.java: nodes in Trie. You will make changes here.
Methods here do not need to be recursive!
Also, if you use a list-like data structure to store children,
then when you add, add nodes in order.
You don't necessarily have to use an OrderedStructure,
although an OrderedStructure could work.
Important: If you choose to use an OrderedStructure
to hold children, you must define an equals() method for
LexiconNode!!!
Miscellaneous Notes
-
Unlike our BT implementation,
our LexiconTrie consists of LexiconNodes.
So in some ways, this is similar to our SLL implementation.
-
Only matchRegexp and suggestCorrections have
to be recursive.
Other methods can be done recursively,
but you will not be penalized in any way if you choose to
implement them iteratively.
Do not make the other methods overly complicated!
Test your code frequently!
Suggested Approach
-
Start with Setion
Managing Node Children
on the handout and implement LexiconNode.
Pick a data structure that will store the children of the node.
Work through the methods in LexiconNode.
Note that to compare chars,
you can just subtract one character from another.
-
After completing LexiconNode.java,
move on to LexiconTrie.java.
You'll need to add a constructor.
The constructor should create a single LexionNode that
has the character assigned to be ' ' (just a blank space).
-
Section
Searching Words and Prefixes
describes constainsWord and containsPrefix.
The technique used in both of these methods is basically the same.
containsWord performs one additional test before returning
to see if the isWord flag is set to be true.
You may want to create a helper method called "find(String word)"
that returns null or a LexiconNode to be helpful here.
Note that you can implement this method with or without recursion!
Either way is acceptable.
-
Move on to addWord and addWordsFromFile.
addWordsFromFile will use a Scanner to
parse an input file (line by line, with a single word per line)
and call addWord for each line.
Be sure to update size.
Convert everything to lowercase, too.
-
removeWord may be implemented recursively or iteratively.
If you choose to do it recursively, you may want to use a helper method.
Either way, be sure to return true if the word appeared in the
lexicon and was removed, and false otherwise.
This method is tricky, so think before you type!
-
For the iterator
(section Other Trie Operations
on the handout),
create a helper method that recursively builds a Vector of words.
Keep in mind that the LexiconNodes already maintain a
list of their children in sorted order.
That will help you iterate over the trie in alphabetical order easily.
-
Section Optional Extensions
describes optional extensions for the lab.
In these sections,
you implement two recursive methods for manipulating the trie.
You may create helper methods as needed for both of these methods.
Think about printSubsetSum and countSubsetSum from
the Recursion Lab for inspiration.