0
0
DSA Javascriptprogramming~10 mins

BST Delete Operation in DSA Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find the minimum value node in a BST.

DSA Javascript
function findMinNode(node) {
  while (node.[1] !== null) {
    node = node.[1];
  }
  return node;
}
Drag options to blanks, or click blank then click option'
Achild
Bright
Cparent
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' will find the maximum, not minimum.
2fill in blank
medium

Complete the code to delete a node with no children (leaf node) in BST.

DSA Javascript
if (node.left === null && node.right === null) {
  node = [1];
}
Drag options to blanks, or click blank then click option'
Anull
Bnode.right
Cnode.parent
Dnode.left
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning node.left or node.right instead of null.
3fill in blank
hard

Fix the error in the code to correctly replace a node with its right child when left child is null.

DSA Javascript
if (node.left === null) {
  node = node.[1];
}
Drag options to blanks, or click blank then click option'
Aright
Bchild
Cleft
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' causes wrong replacement.
4fill in blank
hard

Fill both blanks to correctly find the inorder successor and replace the node's value.

DSA Javascript
let temp = findMinNode(node.[1]);
node.[2] = temp.data;
Drag options to blanks, or click blank then click option'
Aright
Bleft
Cdata
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using left subtree or wrong property name for replacement.
5fill in blank
hard

Fill all three blanks to complete the recursive delete function for BST.

DSA Javascript
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;
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using right subtree for keys less than node data.
Returning wrong child when left is null.