def delete(selfp)"""remove the item at given position ""inherited from linkedbinarytree self validate(pif self left(pand self right( ) has two children replacement self subtree last position(self left( )from linkedbinarytree self replace(preplacement element) replacement now has at most one child parent self parent(pinherited from linkedbinarytree self delete(pif root deletedparent is none self rebalance delete(parentdef delitem (selfk)"""remove item associated with key (raise keyerror if not found""if not self is empty) self subtree search(self root)kif = key)self delete(prely on positional version return successful deletion complete hook for balanced tree subclasses self rebalance access(praise keyerrorkey errorrepr( )code fragment support for deleting an item from treemaplocated either by position or by key performance of binary search tree an analysis of the operations of our treemap class is given in table almost all operations have worst-case running time that depends on hwhere is the height of the current tree this is because most operations rely on constant amount of work for each node along particular path of the treeand the maximum path length within tree is proportional to the height of the tree most notablyour implementations of map operations getitem setitem and delitem each begin with call to the subtree search utility which traces path downward from the root of the treeusing ( time at each node to determine how to continue the search similar paths are traced when looking for replacement during deletionor when computing position' inorder predecessor or successor we note that although single call to the after method has worst-case running time of ( )the successive calls made during call to iter require total of (ntimesince each edge is traced at most twicein sensethose calls have ( amortized time bounds similar argument can be used to prove the ( hworst-case bound for call to find range that reports results (see exercise -