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 replacing with inorder successor or predecessor 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 leaf 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 has one child
BNode has two children
CNode is a leaf
DNode is the root
✗ 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?
ASmallest node in right subtree
BLargest node in left subtree
CParent node
DAny leaf node
✗ Incorrect
The inorder successor is the smallest node in the right subtree.
How do you delete a leaf node in a BST?
AReplace it with inorder successor
BReplace it with inorder predecessor
CRemove it by setting parent's pointer to null
DSwap with root node
✗ Incorrect
A leaf node can be removed by setting its parent's pointer to null.
If a node has only one child, how is deletion handled in a BST?
AReplace node with inorder successor
BDelete node and all its children
CReplace node with inorder predecessor
DReplace node with its child
✗ Incorrect
The node is replaced by its single child to maintain BST structure.
Why is it important to maintain BST properties after deletion?
ATo ensure efficient search, insert, and delete operations