Methods that remain to be implemented in the Trie class have been marked with TODO for easy identification.
The SortedList class encapsulates an ArrayList, to add the functionality of being sorted, while preventing a user from accidentally adding new nodes in an unsorted fashion. Most of our methods are mere wrappers for the corresponding ArrayList methods, except the insert method, which implements an insertionSort algorithm.
getChildWith
method should use the functionality of the
SortedArray to perform a linear search for a child Trie corresponding to the
given character. If a matching child Trie is not found, this
method should return null.
contains
and add
methods of the Trie.
Contains ask the question: Is the given value a suffix of this Trie? Walk through the
tree, moving down to the appropriate child for each character
in value. If you fall off the tree, return false, otherwise
return true when the last child is contained in the Trie.
Add is implemented in a similar manner. Walk through the value, and add a new chain of Trie nodes, one for each letter that is not already found in the Trie. Mark the last Trie node as contained.
remove
a word from the Trie. This method should
walk down the tree, following the appropriate child, and save
the parent if there are other viable paths or if the parent
is the end of another word. Unmark the last node. Then
if it was an only child, remove the unneeded chain of
nodes from the last good parent.
First, the inorder
method will return an ArrayList of all
possible words to be created from a given Trie node. If the node is in the
middle of the Trie, it will only be returning suffixes.
Second, the successorsTo
method will return an ArrayList
of all possible words to be created following a given prefix. The prefix
should be included in the words returned.