In summary, Ternary Seach Trees were proposed by Bentley and Sedgewick1 as an optimal option for sorting and searching multikey data, specially when the keys are character strings.
Figure 1 illustrates the pseudocode of the operations for the
ADT TST. Figure 2 shows the UML diagram for the class TST, and Figure 3
for the struct TSTNode.
// TSTNode is the type of the items stored in the tree
+ TST()
// Creates an empty TST.
+ virtual ~TST()
// Destroys a TST.
+ void readDictionary (const string & file_name)
// Reads the file file_name
// Stores each line as one string in a TST.
+ void insertString (const string & string_ref)
// Adds the string string_ref to the TST.
+ bool hasString(const string & string_ref) const
// Returns true if the string string_ref exists in the TST.
// Otherwise, returns false.
+ void printCompletions(const string & string_ref) const
// Prints, in alphabetical order, all words in the TST
// that have string_ref as prefix.
- bool hasPrefix (const string & string_ref,
TSTNode * & node_ptr, int & char_idx) const
// Auxiliary function.
// Searches for the node corresponding to the prefix string_ref.
// If it finds the node, it sets node_ptr to a pointer to
// the respective node, and returns true.
// If is does not find the node, it sets node_ptr to a pointer to
// the last node found, char_idx to the index of the
// character in the prefix string associated with that node, and
// returns false.
|


Enter name of dictionary file: dictionary.txt Enter word (0 to end): batman List of completions for the prefix "batman": batman ------------------------------------------------- Enter word (0 to end): acceen List of completions for the prefix "acceen": No completions found for the prefix "acceen". ------------------------------------------------- Enter word (0 to end): accen List of completions for the prefix "accen": accend accendibility accendible accension accensor accent accented accenting accentless accentor accentuable accentual accentuality accentually accentuate accentuated accentuating accentuation ------------------------------------------------- Enter word (0 to end): 0 |
1. This is not an easy assignment as it may seem to be. You should start early and consider the following hints:
2. Keep in mind the following considerations: