Question: Python Language: Modify the implementation of the BinarySearchTreeMap class, so in addition to all the functionality it already allows, it will also support the following
Python Language: Modify the implementation of the BinarySearchTreeMap class, so in addition to all the functionality it already allows, it will also support the following method: def get_ith_smallest(self, i) This method should support indexing. That is, when called on a binary search tree, it will return the i-th smallest key in the tree (for i=1 it should return the smallest key, for i=2 it should return the second smallest key, etc.). For example, your implementation should behave as follows: >>> bst = BinarySearchTreeMap() >>> bst[7] = None >>> bst[5] = None >>> bst[1] = None >>> bst[14] = None >>> bst[10] = None >>> bst[3] = None >>> bst[9] = None >>> bst[13] = None >>> bst.get_ith_smallest(3) 5 >>> bst.get_ith_smallest(6) 10 >>> del bst[14] >>> del bst[5] >>> bst.get_ith_smallest(3) 7 >>> bst.get_ith_smallest(6) 13 Implementation requirements: 1. The runtime of the existing operations should remain as before (worst case of ?(height)). The runtime of the get_ith_smallest method should also be worst case of ?(?eight). 2. You should raise an IndexError exception in case i is out of range.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
