Programming Assignment (Dictionary lookup and autocomplete using Tries)Important Information
TrieA trie is a special rooted tree. that allows us to store a set of words by sharing their common prefixes. Example # 1Consider the following list of five words: hello, jello, he, hello, jelly The trie data structure for this list above is given below:
A trie node can be of three types:
Note that a word-ending node need not be a leaf. Also, such nodes are associated with a number that represents the frequency of the corresponding word. Each trie edge is labelled with an alphabet. Reading the words in the dictionary.Starting from the root (diamond node), as we traverse a path along the trie, the letters along a path form a word. Whenever we encounter a word-ending node, we can stop and read off a valid word in the dictionary. For instance, we note the correspondence between the list of words: hello, hello, jello, he, jelly and the paths in the trie. Note
The word he is a prefix of the word hello. Therefore, in the trie, starting from the root, we see that a word-ending node corresponding to he is extended by the suffix “llo” to form a word-ending node for hello. The frequency of occurrence of a word is the number associated with its corresponding word-ending node. Notice how the frequency of “he” is 1 but the frequency of “hello” is 2. Finally, two words with a common prefix such as “jelly” and “jello” will share a common path corresponding to the prefix “jell” in the trie. Trie Data Structure: SpecificationA trie (or a prefix tree) data structure allows us to store a set of strings from a dictionary along with a frequency count for each strings. The following operations should be supported:
ExampleWe will illustrate the process of constructing a trie using an example. At the beginning the empty trie is simply a root node: Suppose we add the strings in the following order: 'test’,'testament’,'testing’,'ping’,'pin’,'pink’,'pine’,'pint’,'testing’,'pinetree’
Lookup of a WordThe operation lookupWord allows us to count the frequency of a word in a trie. If a word does not belong to a trie, then the frequency is 0. For instance, consider the trie below:
AutocompleteThe operation autoComplete provides a list of “completions” of a given string along with their frequencies.
Trie NodeA trie node structure has the following attributes:
Assignment InstructionsThe downloadable zip file for the assignment has the following contents:
Warning
Do not change the name of the file, the class name or the name of the three methods addWord, lookupWord and autoComplete. Doing so will break the grading script and cause deductions. .
Running a testTo run a test say “test1.spec”, call the python script python trieTester.py test1 This will print a bunch of messages including failure messages and tell you whether the test was passed by your code or not. bash-3.2$ python trieTester.py test1 Upload InstructionsYou are asked to upload a zip file that contains your code with the file trieClass.py containing the class for the trie node as provided in your skeleton. Any extra files you have created for implementing the functionalities can be included. Please do not include anything else. Uploaded filename should be called firstname_lastname.zip. Do not “submit for grading” on moodle unless your assignment is really final. Reopening submissions causes enormous problems on moodle. |