Complete Following Code Please Class Trienode Def Init Self Leaf False Selfleaf Leaf Selfc Q37090664

Instructions from your teacher Auto Complete In this assignment, you will create a function to implement the auto complete fecan you complete the followingcode please.

class TrieNode:
def __init__(self, leaf=False):
self.leaf = leaf
self.__children = {}

def addChild(self, letter, leaf=False):
self.__children[letter] = TrieNode(leaf)
return self.__children[letter]

def getChild(self, letter):
return self.__children.get(letter, None)
  
def getFirstChild(self):
“””
This function gets you the first child of this node
“””
return next(iter(self.__children.items()))

def insert_trie(root, word):
cur_node = root
for letter in word:
next_node = cur_node.getChild(letter)
if next_node is None:
next_node = cur_node.addChild(letter)
cur_node = next_node
cur_node.leaf = True

def autocomplete(root, word):
“””
This function should return None if word is not a prefix of anywords in the trie,
otherwise it should return any word in the trie

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.