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?
Because it maintains the BST property by ensuring all left subtree nodes are smaller and right subtree nodes are larger than the replaced node.
Click to reveal answer
beginner
What happens if you delete a leaf node in a BST?
You simply remove the node by setting its parent's pointer to NULL, as it has no children.
Click to reveal answer
Which case requires finding the inorder successor or predecessor during BST deletion?
ANode with one child
BNode with two children
CNode with no children
DRoot node only
✗ Incorrect
Only when the node has two children do we replace it with its inorder successor or predecessor.
What is the inorder successor of a node in a BST?
AAny leaf node
BLargest node in left subtree
CParent node
DSmallest node in right subtree
✗ Incorrect
The inorder successor is the smallest node in the right subtree.
When deleting a leaf node in a BST, what is the main action?
AReplace with inorder successor
BReplace with inorder predecessor
CRemove the node by setting parent's pointer to NULL
DSwap with root node
✗ Incorrect
Leaf nodes are removed by setting the parent's pointer to NULL.
If a node has only one child, how is deletion handled in a BST?
AReplace node with its child
BReplace node with inorder successor
CReplace node with inorder predecessor
DRemove node and set parent's pointer to NULL
✗ Incorrect
The node is replaced by its single child to maintain the BST structure.
Why do we not simply remove a node with two children without replacement?
AIt would break the BST property
BIt is faster to replace
CIt is easier to code
DIt does not matter
✗ Incorrect
Removing a node with two children without replacement breaks the BST property.
Explain the steps to delete a node with two children in a BST.
Think about how to keep the tree sorted after deletion.
You got /4 concepts.
Describe how deleting a node with one child differs from deleting a leaf node in a BST.
Consider what happens to the child nodes.
You got /4 concepts.
Practice
(1/5)
1. What happens when you delete a leaf node (a node with no children) from a Binary Search Tree (BST)?
easy
A. The node is replaced by its right child.
B. The entire tree is restructured to maintain balance.
C. The node is replaced by its left child.
D. The node is simply removed and its parent's pointer is set to null.
Solution
Step 1: Understand leaf node deletion
A leaf node has no children, so removing it does not affect other nodes.
Step 2: Update parent's pointer
After removal, the parent's pointer to this node is set to null to disconnect it.
Final Answer:
The node is simply removed and its parent's pointer is set to null. -> Option D
Quick Check:
Leaf node deletion = remove node and set parent's pointer null [OK]
Hint: Leaf node deletion just removes node, no child replacement needed [OK]
Common Mistakes:
Replacing leaf node with child when none exists
Restructuring entire tree unnecessarily
Confusing leaf node with internal node deletion
2. Which of the following is the correct syntax to delete a node with value key from a BST in C?
easy
A. root = deleteNode(root, key);
B. deleteNode(root, key);
C. delete(root, key);
D. root.deleteNode(key);
Solution
Step 1: Understand function call and assignment
Deleting a node may change the root, so the returned root must be assigned back.
Step 2: Check syntax correctness
root = deleteNode(root, key); correctly assigns the returned root from deleteNode to root.
Final Answer:
root = deleteNode(root, key); -> Option A
Quick Check:
Assign returned root after deletion [OK]
Hint: Always assign returned root after deletion to handle root changes [OK]
Common Mistakes:
Not assigning returned root causing lost tree updates
Using incorrect function names
Using object-oriented syntax in C
3. Given the BST below and the code snippet to delete node with value 15: