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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!