Introduction
The Delete Node in a BST problem is one of the most important Binary Search Tree interview questions because it combines:
- BST traversal
- Tree restructuring
- Recursive thinking
- Node replacement logic
- Tree manipulation
Unlike searching or insertion, deletion is slightly more complex because we must maintain BST properties after removing a node.
This problem is frequently asked in coding interviews and online assessments.
Problem Link
🔗 LeetCode 450 – Delete Node in a BST
Problem Statement
Given:
- The root of a Binary Search Tree
- A key value
Delete the node containing the key while preserving BST properties.
Return the updated BST root.
BST Property Reminder
In a Binary Search Tree:
After deletion:
- Tree must still remain a valid BST.
Example 1
Input
Output
Visualization
Before deletion:
After deleting 3:
Key Deletion Cases
BST deletion has 3 important cases.
Case 1: Node Has No Child
Simply remove the node.
Case 2: Node Has One Child
Replace the node with its child.
Case 3: Node Has Two Children
This is the tricky part.
We:
- Find inorder predecessor or successor
- Replace node
- Reconnect subtrees properly
Intuition
Suppose we want to delete:
from:
Since node 3 has:
- Left child
- Right child
we cannot directly delete it.
Instead:
- Attach right subtree to rightmost node of left subtree
- Return left subtree as replacement
This preserves BST ordering.
Brute Force Approach
Idea
- Store inorder traversal
- Remove target node
- Rebuild BST
Why Brute Force is Bad
Problems:
- Extra memory usage
- Rebuilding tree is expensive
- Unnecessary traversal
Brute Force Complexity
Time Complexity
Space Complexity
Optimized BST Deletion Approach
Use BST properties to:
- Search efficiently
- Modify only required nodes
- Preserve tree structure
Java Solution
How This Solution Works
The main logic happens inside:
This function deletes the node safely.
Understanding solve()
Case 1
If:
return right subtree.
Case 2
If:
return left subtree.
Case 3
If both children exist:
- Save right subtree
- Find rightmost node in left subtree
- Attach right subtree there
- Return left subtree
Why Rightmost Node?
Because:
is the:
This maintains BST ordering perfectly.
Dry Run
Input
Step 1
Search node:
Step 2
Node has:
- Left child = 2
- Right child = 4
Step 3
Find rightmost node in left subtree.
Rightmost node:
Step 4
Attach right subtree:
Step 5
Return left subtree:
Updated BST becomes valid.
Time Complexity Analysis
Best Case
Balanced BST.
Worst Case
Skewed BST.
Space Complexity
Recursive Helper
where:
Alternative Recursive Approach
Another common method:
- Replace node with inorder successor
- Delete successor recursively
This approach is also interview friendly.
Interview Explanation
In interviews explain:
When deleting a node with two children, we preserve BST properties by connecting the right subtree to the rightmost node of the left subtree.
This demonstrates:
- BST restructuring knowledge
- Tree manipulation skills
- Recursive reasoning
- Pointer management
Common Mistakes
1. Forgetting BST Property
Deletion should not break ordering.
2. Losing Subtrees
Always reconnect children carefully.
3. Incorrect Node Replacement
Many candidates replace node incorrectly.
4. Not Handling Null Cases
Always check:
properly.
FAQs
Q1. Why is BST deletion difficult?
Because tree structure must remain valid after removal.
Q2. Why use rightmost node of left subtree?
It is the largest smaller value.
Perfect replacement candidate.
Q3. Can we use inorder successor instead?
Yes.
Both predecessor and successor approaches work.
Q4. What is deletion complexity?
Balanced BST:
Worst case:
Related BST Problems
Practice these next:
- Insert into BST
- Search in BST
- Validate BST
- Lowest Common Ancestor in BST
- Kth Smallest Element in BST
- Inorder Successor in BST
Conclusion
Delete Node in BST is one of the most important BST interview problems because it teaches:
- Tree restructuring
- Recursive manipulation
- Pointer handling
- BST property maintenance
The key insight is:
When deleting a node with two children, reconnect subtrees carefully so BST ordering remains valid.
Mastering this problem makes advanced BST operations significantly easier.





