Complete the code to create a new node with the given value.
class Node: def __init__(self, val): self.val = val self.left = None self.right = None new_node = Node([1])
The new node is created with the value 5 passed as an argument.
Complete the code to check if the current node is empty before inserting.
def insert(root, val): if root is [1]: return Node(val)
We check if the root is None to know if the tree or subtree is empty.
Fix the error in the recursive call to insert the value in the left subtree.
def insert(root, val): if val < root.val: root.left = insert(root.[1], val) return root
To insert in the left subtree, we recurse on root.left.
Fill both blanks to insert the value in the right subtree when val is greater or equal.
def insert(root, val): if val >= root.val: root.[1] = insert(root.[2], val) return root
For values greater or equal, insert into the right subtree using root.right.
Fill all three blanks to complete the BST insert function with base case and recursive calls.
def insert(root, val): if root is [1]: return Node(val) if val < root.val: root.left = insert(root.left, [2]) else: root.right = insert(root.right, [3]) return root
The base case checks if root is None. The recursive calls pass the value to insert.
