What are the three main cases to consider when deleting a node in a Binary Search Tree (BST)?
1. Node to delete is a leaf (no children). 2. Node to delete has one child. 3. Node to delete has two children.
Click to reveal answer
intermediate
In BST deletion, how do you handle deleting a node with two children?
Replace the node's value with its inorder successor (smallest value in right subtree) or inorder predecessor (largest value in left subtree), then delete that successor/predecessor node.
Click to reveal answer
beginner
What is the inorder successor in a BST?
The node with the smallest value in the right subtree of a given node.
Click to reveal answer
intermediate
Why do we replace a node with its inorder successor or predecessor when deleting a node with two children in a BST?
To maintain the BST property where left subtree nodes are smaller and right subtree nodes are larger than the node, ensuring the tree remains correctly ordered after deletion.
Click to reveal answer
beginner
What happens if you delete a leaf node in a BST?
You simply remove the leaf node by setting its parent's pointer to null, as it has no children.
Click to reveal answer
Which of the following is NOT a case to consider when deleting a node in a BST?
ANode has no children
BNode has three children
CNode has one child
DNode has two children
✗ Incorrect
In a BST, a node can have at most two children, so 'three children' is not a valid case.
When deleting a node with two children, which node is commonly used to replace it?
AInorder successor
BRoot node
CRandom leaf node
DInorder predecessor
✗ Incorrect
The inorder successor (smallest node in the right subtree) is commonly used to replace a node with two children.
What is the inorder successor of a node in a BST?
AAny leaf node
BLargest node in left subtree
CRoot node
DSmallest node in right subtree
✗ Incorrect
The inorder successor is the smallest node in the right subtree of the node.
If a node to delete has only one child, what is the deletion process?
AReplace node with its child
BReplace node with root
CDelete node and all children
DReplace node with inorder successor
✗ Incorrect
If the node has one child, replace the node with its child to maintain BST structure.
What happens to the BST property after deleting a node and replacing it with its inorder successor?
ABST property is broken
BTree becomes unbalanced
CBST property is maintained
DTree becomes empty
✗ Incorrect
Replacing with inorder successor maintains the BST property because the successor fits correctly in the node's position.
Explain the steps to delete a node with two children in a Binary Search Tree.
Think about how to keep the tree ordered after deletion.
You got /4 concepts.
Describe how deleting a leaf node differs from deleting a node with one child in a BST.
Consider the number of children and how the tree links change.
You got /4 concepts.
Practice
(1/5)
1. What happens when you delete a leaf node (a node with no children) in a Binary Search Tree (BST)?
easy
A. The entire tree is rebuilt
B. The node is replaced by its right child
C. The node is replaced by its left child
D. The node is simply removed without affecting other nodes
Solution
Step 1: Understand leaf node deletion
A leaf node has no children, so deleting it means just removing it from the tree.
Step 2: Effect on the BST
Since it has no children, no other nodes need to be moved or replaced.
Final Answer:
The node is simply removed without affecting other nodes -> Option D
Quick Check:
Leaf node deletion = simple removal [OK]
Hint: Leaf nodes delete by direct removal only [OK]
Common Mistakes:
Thinking children need rearrangement
Replacing leaf with child nodes
Rebuilding the whole tree
2. Which of the following is the correct TypeScript function signature for deleting a node from a BST?
easy
A. function deleteNode(key: number): TreeNode
B. function deleteNode(root: number, key: TreeNode): void
C. function deleteNode(root: TreeNode | null, key: number): TreeNode | null
D. function deleteNode(root: TreeNode, key: string): TreeNode
Solution
Step 1: Analyze parameter types
The root should be a TreeNode or null, and key should be a number to identify the node.
Step 2: Analyze return type
The function returns the updated root node or null if tree becomes empty.
Final Answer:
function deleteNode(root: TreeNode | null, key: number): TreeNode | null -> Option C
Quick Check:
Correct parameter and return types = function deleteNode(root: TreeNode | null, key: number): TreeNode | null [OK]
Hint: Root can be null; key is number; returns updated root [OK]
Common Mistakes:
Swapping parameter types
Using wrong return type
Using string instead of number for key
3. Given the BST below and the delete operation deleteNode(root, 10), what is the in-order traversal of the BST after deletion?
BST structure: 15 / \ 10 20 / \ \ 8 12 25
medium
A. [8, 12, 15, 20, 25]
B. [8, 10, 12, 15, 20, 25]
C. [8, 15, 20, 25]
D. [12, 15, 20, 25]
Solution
Step 1: Delete node 10 with two children
Node 10 has two children (8 and 12). Replace it with its inorder successor, which is 12.
Step 2: Remove node 12 from its original position
After replacement, remove node 12 from right subtree of 10.
Hint: Replace node with inorder successor for two children [OK]
Common Mistakes:
Not replacing node 10 correctly
Leaving node 10 in tree
Incorrect traversal order
4. Consider this TypeScript code snippet for deleting a node from a BST. What is the bug?
function deleteNode(root: TreeNode | null, key: number): TreeNode | null {
if (!root) return null;
if (key < root.val) {
root.left = deleteNode(root.left, key);
} else if (key > root.val) {
root.right = deleteNode(root.right, key);
} else {
if (!root.left) return root.right;
if (!root.right) return root.left;
let minNode = findMin(root.right);
root.val = minNode.val;
deleteNode(root.right, minNode.val);
}
return root;
}
medium
A. No return statement after deletion
B. Missing assignment of root.right after deleting minNode
C. Wrong comparison operators for key
D. Incorrect base case for empty root
Solution
Step 1: Analyze deletion of minNode
After copying minNode's value, the code calls deleteNode on root.right but does not assign the result back to root.right.
Step 2: Effect of missing assignment
Without assignment, the minNode is not removed from the right subtree, causing duplicate values.
Final Answer:
Missing assignment of root.right after deleting minNode -> Option B
Quick Check:
Assign updated subtree after deletion [OK]
Hint: Always assign recursive delete result back to subtree [OK]
Common Mistakes:
Forgetting to assign after recursive delete
Misplacing base case
Using wrong comparison signs
5. You have a BST with nodes: 30, 20, 40, 10, 25, 35, 50. You delete node 30 (root). Which node becomes the new root after deletion using the standard BST delete operation?
hard
A. 35
B. 25
C. 40
D. 20
Solution
Step 1: Identify node 30's children
Node 30 has two children: left subtree with 20 and right subtree with 40.
Step 2: Find inorder successor of 30
Inorder successor is the smallest node in right subtree, which is 35.
Step 3: Replace 30 with 35 and delete 35 from right subtree
35 replaces 30 as root, and 35 is removed from its original position.
Final Answer:
35 -> Option A
Quick Check:
Inorder successor replaces deleted node [OK]
Hint: Use inorder successor (smallest right subtree) for two-child node deletion [OK]
Common Mistakes:
Using inorder predecessor instead
Choosing wrong replacement node
Not updating root after deletion
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.