0
0
DSA Typescriptprogramming~10 mins

BST Delete Operation in DSA Typescript - Interactive Practice

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

Complete the code to check if the current node is null before deletion.

DSA Typescript
if (root === [1]) {
    return root;
}
Drag options to blanks, or click blank then click option'
Aundefined
B0
Cnull
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined instead of null causes the check to fail.
Using 0 or false is incorrect because nodes are objects, not booleans or numbers.
2fill in blank
medium

Complete the code to move left or right in the BST based on the key value.

DSA Typescript
if (key < root.val) {
    root.left = deleteNode(root.left, [1]);
} else if (key > root.val) {
    root.right = deleteNode(root.right, key);
}
Drag options to blanks, or click blank then click option'
Akey
Broot.val
Croot.left
Droot.right
Attempts:
3 left
💡 Hint
Common Mistakes
Passing root.val instead of key causes wrong recursion.
Passing root.left or root.right is incorrect because those are nodes, not keys.
3fill in blank
hard

Fix the error in finding the minimum value node in the right subtree.

DSA Typescript
let minNode = root.right;
while (minNode.[1] !== null) {
    minNode = minNode.left;
}
Drag options to blanks, or click blank then click option'
Aright
Bleft
Cval
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Checking minNode.right in the while condition causes infinite loop or wrong node.
Using minNode.val or minNode.parent is incorrect for traversal.
4fill in blank
hard

Fill both blanks to replace the node's value with the minimum node's value and delete the minimum node.

DSA Typescript
root.val = minNode.[1];
root.right = deleteNode(root.right, [2]);
Drag options to blanks, or click blank then click option'
Aval
Bleft
CminNode.val
DminNode.left
Attempts:
3 left
💡 Hint
Common Mistakes
Using minNode.left or minNode.right instead of minNode.val causes errors.
Passing minNode.left instead of minNode.val to deleteNode causes wrong deletion.
5fill in blank
hard

Fill all three blanks to handle the case when the node to delete has only one child.

DSA Typescript
if (root.left === null) {
    return root.[1];
} else if (root.right === null) {
    return root.[2];
}

// Node with two children handled later

return [3];
Drag options to blanks, or click blank then click option'
Aleft
Bright
Croot
DdeleteNode(root.left, key)
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right in returns causes wrong tree structure.
Returning deleteNode call instead of root in last blank causes infinite recursion.