Question: Write the code for the maximum() and methods in Python 3.7 language: class BinarySearchTree: Binary Search Tree class. This class represents a binary tree satisfying
Write the code for the maximum() and
methods in Python 3.7 language:




class BinarySearchTree: ""Binary Search Tree class. This class represents a binary tree satisfying the Binary Search Tree property: for every node, its value is all items stored in its left subtree, and -self-root. def init__(self, root: Optional [Any]) None: """Initialize a new BST containing only the given root value. If is None, initialize an empty tree if root is None: self. root - None self. left - None self._right - None else: self._root - root self._left-BinarySearchTree (None) self._right - BinarySearchTree (None) def is_empty (self) - bool: ""Return True if this BST is empty. >>> bst- BinarySearchTree (None) >>>bst.is_empty() True >>> bstBinarySearchTree (10) >>bst.is_empty() False return self._root is None def maximum(self) -Optional[int]: "Return the maximum number in this BST, or None if this BST is empty Hint: Review the BST property to ensure you aren' t making unnecessary recursive calls. >>> BinarySearchTree (None), maximum() is None True >>BinarySearchTree(10).maximum() 10 >>> bst - BinarySearchTree(7) >>>leftBinarySearchTree(3) >>left._left BinarySearchTree(3) >>left._rightBinarySearchTree(5) >>>right - BinarySearchTree(11) >>>right._leftBinarySearchTree(9) >>>right._rightBinarySearchTree(13) >>>bst._left -left >>bst._right - right >>bst.maximum () 13 # Empty BST if self.is_empty(): return None # ADD CODE HERE def count (self, item: Any) int: "Return the number of occurrences of
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
