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 the current 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?
Because it maintains the BST property by ensuring all left subtree nodes are smaller and all 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 leaf node by setting its parent's pointer to null.
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 one child
CNode has three children
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
DParent node
✗ Incorrect
The inorder successor (smallest node in right subtree) is used to replace the deleted node to maintain BST properties.
What is the inorder successor of a node in a BST?
ASmallest node in right subtree
BParent node
CLargest node in left subtree
DAny leaf node
✗ 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 inorder successor
BRemove the node and connect its child directly to its parent
CReplace node with inorder predecessor
DDo nothing
✗ Incorrect
The node is removed and its single child is linked directly to the node's parent.
What happens to the BST property after deleting a node and replacing it with its inorder successor?
ABST becomes empty
BBST property is broken
CBST becomes a linked list
DBST property is maintained
✗ Incorrect
Replacing with inorder successor maintains the BST property because the successor fits correctly in the tree order.
Explain the steps to delete a node with two children in a BST.
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 connections between 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 simply removed without affecting other nodes.
B. The entire tree is rebuilt from scratch.
C. The node's children replace it in the tree.
D. The root node is always changed.
Solution
Step 1: Understand leaf node deletion
A leaf node has no children, so removing it does not affect other nodes.
Step 2: Effect on BST structure
Since no children exist, simply remove the node and update its parent's pointer to null.
Final Answer:
The node is simply removed without affecting other nodes. -> Option A
Quick Check:
Leaf node deletion = simple removal [OK]
Hint: Leaf nodes delete by direct removal only [OK]
Common Mistakes:
Thinking children replace the node when none exist
Assuming root always changes
Believing tree rebuild is needed
2. Which of the following is the correct syntax to delete a node with value key from a BST in JavaScript?
easy
A. bst.deleteNode(key);
B. bst.delete(key);
C. bst.remove(key);
D. bst.erase(key);
Solution
Step 1: Identify common BST delete method
In many JavaScript BST implementations, the method to delete a node is named delete.
Step 2: Check method naming conventions
Methods like remove, erase, or deleteNode are not standard or common in JavaScript BST examples.
Final Answer:
bst.delete(key); -> Option B
Quick Check:
Standard BST delete method = delete() [OK]
Hint: Use bst.delete(key) to remove nodes [OK]
Common Mistakes:
Using remove() or erase() which are not standard
Confusing delete keyword with method name
Using deleteNode() which is uncommon
3. Consider this BST and the delete operation:
10
/ \
5 15
/ \
12 20
What will be the in-order traversal output after deleting node with value 15?
medium
A. [5, 10, 12, 15, 20]
B. [5, 10, 20]
C. [5, 10, 12, 20]
D. [5, 10, 15, 20]
Solution
Step 1: Identify node to delete and its children
Node 15 has two children: 12 (left) and 20 (right).
Step 2: Replace node 15 with its in-order successor
The in-order successor is the smallest node in right subtree, which is 20. Replace 15 with 20 and delete original 20 node.