Question: want to create a prefix tree in python (3) 2 ADTs Node and PrefixTree Looking to create Node class with : -__contains__(letter) - returns true
want to create a prefix tree in python (3)
2 ADTs Node and PrefixTree
Looking to create Node class with :
-__contains__(letter) - returns true if the Node has a child corresponding to the letter
-__getitem__(let) - returns the child node corresponding to the letter
-add_sub(tok, value) - adds a child to the node under the given token, also handle the case if a child already exists (it should only change the value of the child)
-remove_sub(let) - removes the child node corresponding to a given letter
this is the ADT:
class Node: def __init__(self, value = None): self.subs = {} self._value = value self.last = True
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
