Complete the code to return the maximum value in a BST.
def find_max(root): current = root while current.[1] is not None: current = current.right return current.data
The maximum element in a BST is found by going to the rightmost node. So, we keep moving to the right child until there is no right child left.
Complete the code to handle the case when the BST is empty.
def find_max(root): if [1] is None: return None current = root while current.right is not None: current = current.right return current.data
We check if the root itself is None to handle an empty tree. If it is None, we return None as there is no maximum element.
Fix the error in the loop condition to correctly find the maximum element.
def find_max(root): current = root while current.[1] != None: current = current.right return current.data
The loop should continue while the right child exists. Using 'right' ensures we move to the rightmost node which holds the maximum value.
Fill both blanks to create a function that returns the maximum value or None if the tree is empty.
def find_max(root): if root is [1]: return [2] current = root while current.right is not None: current = current.right return current.data
If the root is None, it means the tree is empty, so we return None. This handles the empty tree case safely.
Fill all three blanks to create a safe function that finds the maximum element in a BST.
def find_max(root): if [1] is None: return [2] current = [3] while current.right is not None: current = current.right return current.data
First, check if root is None to handle empty tree. Return None if empty. Then start traversal from root to find the rightmost node which holds the maximum value.
