trietester.py
class MyTrie: def exists(self, word, position=0): def isTerminal(self): def autoComplete(self, prefix,position=0): def __len__(self): |
#trietester.py # You will need the ‘american-english-no-accents’file in the directory of the tester import random wordlist = [] def GenerateWord(size): def Test(lib, seed=0, size=10, rounds=10, verbose=False,wordlist=[]): if not lib: if not wordlist: random.seed(a=seed) trie = lib.MyTrie() for word in wordlist: if len(wordlist) != len(trie): if verbose: for j in range(0, rounds): ifrandom.randint(0,2) == 0: try: if not(mlist == wordlist): try: if verbose: for j in range(0,rounds): matchlist =list(filter(lambda x: x.startswith(prefix), wordlist)) if verbose: if __name__ == “__main__”: if len(sys.argv) < 2: |
american-english-no-accents.txt
A
A’s
AA’s
AB’s
ABM’s
AC’s
ACTH’s
AI’s
AIDS’s
AM’s
AOL
AOL’s
ASCII’s
ASL’s
ATM’s
ATP’s
AWOL’s
AZ’s
AZT’s
Aachen
Aaliyah
Aaliyah’s
Aaron
Abbas
Abbasid
Abbott
Abbott’s
Abby
Abby’s
Abdul
Abdul’s
Abe
Abe’s
Abel
Abel’s
Abelard
Abelson
Abelson’s
Aberdeen
Aberdeen’s
Abernathy
Abernathy’s
Abidjan
Abidjan’s
Abigail
Abilene
Abner
Abner’s
Abraham
Abraham’s
Abram
Abram’s
Abrams
Absalom
Abuja
Abyssinia
Abyssinia’s
Abyssinian
Abyssinian’s
Ac
Ac’s
Acadia
Acadia’s
Acapulco
Acapulco’s
Accenture
Accenture’s
Accra
Accra’s
Acevedo
Acevedo’s
Achaean
Achaean’s
Achebe
Achebe’s
Achernar
Acheson
Acheson’s
Achilles
Achilles’s
Aconcagua
Aconcagua’s
Acosta
Acosta’s
Acropolis
Acrux
Acrux’s
Actaeon
Acton
Acts
Acuff
Acuff’s
Ada
Ada’s
Adam
Adam’s
Adams
Adan
Adan’s
Adana
Python Topics: Tries, recursion Summary: Given: You are given a Python Class template, and a list of words in the file ‘american.-english.-no-accents. txt’. In the template Task: Write a recursive trie data structure. Each node should store either a character or a word. Then, implement the autocomplete method. This method shou ld recursively explore the trie and return a list of all words in the trie that match that prefix. The list must be in alphabetical order. Example Given the wo rds ‘dad’, ‘daddy’, ‘daddio’, ‘danny’, and ‘mummy’, the trie should look like this: mum’ d Im a d m dad danny / mum / daddy daddio mummy When the prefix ‘da’ is autocompleted, the list returned should be [‘dad’, ‘daddio’, ‘daddy’, ‘danny’]. When the prefix ” is given, every word in the trie should be returned, in alphabetical order. When the prefix ‘uncl’ is given, an empty list should be returned Notes : Ensure that duplicate words do not get added to the trie twice. Both lower and upper case letters will be used. Consider them as seperate characters, upper case letters coming before lower case. The file ‘american.-english.-no.-ascents.. txt’ is used by the tester but you can write your own test dictionary and tester program Show transcribed image text Python Topics: Tries, recursion Summary: Given: You are given a Python Class template, and a list of words in the file ‘american.-english.-no-accents. txt’. In the template Task: Write a recursive trie data structure. Each node should store either a character or a word. Then, implement the autocomplete method. This method shou ld recursively explore the trie and return a list of all words in the trie that match that prefix. The list must be in alphabetical order. Example Given the wo rds ‘dad’, ‘daddy’, ‘daddio’, ‘danny’, and ‘mummy’, the trie should look like this: mum’ d Im a d m dad danny / mum / daddy daddio mummy When the prefix ‘da’ is autocompleted, the list returned should be [‘dad’, ‘daddio’, ‘daddy’, ‘danny’]. When the prefix ” is given, every word in the trie should be returned, in alphabetical order. When the prefix ‘uncl’ is given, an empty list should be returned Notes : Ensure that duplicate words do not get added to the trie twice. Both lower and upper case letters will be used. Consider them as seperate characters, upper case letters coming before lower case. The file ‘american.-english.-no.-ascents.. txt’ is used by the tester but you can write your own test dictionary and tester program
Expert Answer
Answer to trietester.py class MyTrie: def __init__(self): # Initialize the trie node as needed pass def insert(self, word): # Inse…