Question: This is for python. I have to modify the implementation of the binary search tree to handle duplicate keys properly, which is in the picture
This is for python.
I have to modify the implementation of the binary search tree to handle duplicate keys properly, which is in the picture below.
This implies, if a key already exists in the tree, then the new payload should replace the old value. Do not add another node with the same key!
Determine where the new functionality needs to be added.
Show the printout of your results along with the code. Thanks
Code Part 1

Code Part 2

File Edit Format Run Options Window Help lass BinarySearchTree: def init (self): self.root = None self.size-0 def length (self): return self.size def len(self): return self.size def iter_ (self): return self.root. iter () class TreeNode: def _init__(self, key,val,left-None, right None, parent-None): self . Key = key self.payload val self.leftChild- left self.rightChild -right self.parent -parent def hasLeftChild (self): return self.leftChild def hasRightChild (self): return self.rightChild def isLeftChild (self): return self.parent and self.parent. eftChild == self def isRightChild (self): return self.parent and self.parent.rightChild - self def isRoot (self) return not self.parent def isLeaf (self): return not (self.rightChild or self.leftChild) File Edit Format Run Options Window Help lass BinarySearchTree: def init (self): self.root = None self.size-0 def length (self): return self.size def len(self): return self.size def iter_ (self): return self.root. iter () class TreeNode: def _init__(self, key,val,left-None, right None, parent-None): self . Key = key self.payload val self.leftChild- left self.rightChild -right self.parent -parent def hasLeftChild (self): return self.leftChild def hasRightChild (self): return self.rightChild def isLeftChild (self): return self.parent and self.parent. eftChild == self def isRightChild (self): return self.parent and self.parent.rightChild - self def isRoot (self) return not self.parent def isLeaf (self): return not (self.rightChild or self.leftChild)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
