Complete the code to check if the current node is None.
def is_bst(node): if node is [1]: return True
The base case for recursion is when the node is None, meaning an empty subtree, which is a valid BST.
Complete the code to check if the left child value is less than the current node's value.
def is_bst(node): if node.left and node.left.val [1] node.val: return False
In a BST, the left child's value must be less than the current node's value. If it is greater or equal, it's not a BST.
Fix the error in the recursive call to check the right subtree.
def is_bst(node): if node.right and not is_bst([1]): return False
To check the right subtree, we must recursively call is_bst on node.right.
Fill both blanks to complete the function that checks BST property using min and max limits.
def is_bst_util(node, min_val, max_val): if node is None: return True if node.val [1] min_val or node.val [2] max_val: return False
The node's value must be greater than min_val and less than max_val. If it is less or equal to min_val or greater or equal to max_val, it violates BST rules.
Fill all three blanks to complete the recursive calls for left and right subtrees with updated limits.
def is_bst_util(node, min_val, max_val): if node is None: return True if node.val <= min_val or node.val >= max_val: return False return is_bst_util(node.[1], min_val, node.val) and is_bst_util(node.[2], [3], max_val)
For the left subtree, we call is_bst_util with max_val updated to node.val. For the right subtree, min_val is updated to node.val. The recursive calls use node.left and node.right respectively.
