Complete the code to find the minimum value node in a BST.
function findMinNode(node) {
while (node.[1] !== null) {
node = node.[1];
}
return node;
}In a BST, the minimum value is found by going to the left child repeatedly until null.
Complete the code to delete a node with no children (leaf node) in BST.
if (node.left === null && node.right === null) { node = [1]; }
Deleting a leaf node means setting it to null.
Fix the error in the code to correctly replace a node with its right child when left child is null.
if (node.left === null) { node = node.[1]; }
If the left child is null, replace the node with its right child.
Fill both blanks to correctly find the inorder successor and replace the node's value.
let temp = findMinNode(node.[1]); node.[2] = temp.data;
The inorder successor is the minimum node in the right subtree. Replace node's data with successor's data.
Fill all three blanks to complete the recursive delete function for BST.
function deleteNode(node, key) {
if (node === null) return null;
if (key < node.data) {
node.[1] = deleteNode(node.[2], key);
} else if (key > node.data) {
node.right = deleteNode(node.right, key);
} else {
if (node.left === null) return node.[3];
else if (node.right === null) return node.left;
let temp = findMinNode(node.right);
node.data = temp.data;
node.right = deleteNode(node.right, temp.data);
}
return node;
}When key is less, recurse on left subtree. Replace node.left with recursive call result. If left child is null, return right child.