Complete the code to insert a value into a Binary Search Tree (BST).
def insert(root, val): if root is None: return Node(val) if val < root.val: root.left = insert(root.left, [1]) else: root.right = insert(root.right, val) return root
The value to insert is passed recursively to the left subtree when it is less than the current node's value.
Complete the code to search for a value in a BST.
def search(root, val): if root is None or root.val == [1]: return root if val < root.val: return search(root.left, val) else: return search(root.right, val)
We compare the node's value with the value we are searching for.
Fix the error in the code to find the minimum value node in a BST.
def minValueNode(node): current = node while current.[1] is not None: current = current.left return current
The minimum value in a BST is found by going as far left as possible.
Fill both blanks to create a dictionary comprehension that maps node values to their depths in a BST.
depths = {node.val: [1] for node in nodes if node.val [2] 10 }We map each node's value to its depth, filtering nodes with values less than 10.
Fill all three blanks to create a dictionary comprehension that maps uppercase node values to their depths if depth is greater than 2.
result = { [1]: [2] for node in nodes if node.depth [3] 2 }The keys are uppercase node values, values are depths, filtered by depth greater than 2.
