Delete a node with two children
Standard · Trace the algorithm · about 6 min
Delete 3 from this BST. 3 has two children, so its successor takes its place.
Answer each question before the step plays.
Example 1
Input:
{"values":[8,3,12,1,6,10,14,4,7,5],"key":3}
Output:
[8,4,12,1,6,10,14,null,null,5,7]
The tree after the delete, in level order.
Constraints
- The trace uses the tree shown
- The successor is the smallest key in the right subtree
Learn the idea first: BST delete; successor and predecessor, a visual lesson.
More BST delete; successor and predecessor problems
- Pick the tree after a delete Warm-up
- Implement delete Standard
- Successor Standard
- Spot the bug: lost subtree Standard
- Delete with the predecessor instead Challenge