Complete the code to start the delete operation by checking if the root is None.
def delete_node(root, key): if root is [1]: return root
The base case for deleting a node in a BST is when the root is None, meaning the tree or subtree is empty.
Complete the code to move left in the BST if the key is smaller than the root's value.
if key < root.val: root.left = delete_node(root.[1], key)
If the key to delete is smaller than the root's value, we go to the left subtree to continue searching.
Fix the error in the code to find the minimum value node in the right subtree.
def min_value_node(node): current = node while current.[1] is not None: current = current.left return current
To find the minimum value node, we keep going left until there is no left child. The loop should check current.left to move left if needed. The error is in the attribute checked in the while condition; it should be current.left.
Fill both blanks to replace the root's value with the minimum value in the right subtree and delete that minimum node.
if root.left is None: temp = root.[1] root = None return temp elif root.right is None: temp = root.[2] root = None return temp
If the left child is None, we replace the root with its right child. If the right child is None, we replace the root with its left child.
Fill all three blanks to replace the root's value with the minimum value in the right subtree, then delete that minimum node.
temp = min_value_node(root.[1]) root.val = temp.[2] root.[3] = delete_node(root.[1], temp.val)
We find the minimum node in the right subtree, replace the root's value with that minimum value, then delete the minimum node from the right subtree.
