2-3 Deletion (Element at Leaf)
This lesson will cover the deletion operation in 2-3 trees, discussing all four scenarios based on the position of the element that needs to be deleted.
Deletion Algorithm
Deletion in 2-3 Trees is implemented based on the same scenarios as we discussed for insertion but in the reverse order. The deletion algorithm also takes time. And just like insertion, deletion also begins from the leaf node. The deletion in 2-3 Trees is performed based on these scenarios:
Case 1: Element at Leaf
When the element that needs to be removed is present at the leaf node, we check how many keys are present in that node; this further divides the algorithm into two scenarios:
1.1 Leaf node has more than one key
If the leaf at which the element to be deleted has more than one key, then simply delete the element.
Example: See the following example where the node has more than one key.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.