![]() |
VOOZH | about |
In binary search trees we have seen the average-case time for operations like search/insert/delete is O(log N) and the worst-case time is O(N) where N is the number of nodes in the tree.
Like other Trees include AVL trees, Red Black Tree, B tree, 2-3 Tree is also a height balanced tree.
The time complexity of search/insert/delete is O(log N) .
A 2-3 tree is a B-tree of order 3.
Properties of 2-3 tree:
Search: To search a key K in given 2-3 tree T, we follow the following procedure:
Base cases:
Recursive Calls:
Consider the following example:
Insertion: There are 3 possible cases in insertion which have been discussed below:
In Deletion Process for a specific value:
To Understand the deletion process-
Consider the 2-3 tree given below
delete the following values from it: 69,72, 99, 81.
To delete 69, swap it with its in-order successor, that is, 72. 69 now comes in the leaf node. Remove the value 69 from the leaf node.
To delete 72, 72 is an internal node. To delete this value swap 72 with its in-order successor 81 so that 72 now becomes a leaf node. Remove the value 72 from the leaf node.
Now there is a leaf node that has less than 1 data value thereby violating the property of a 2-3 tree. So the node must be merged.
To merge the node, pull down the lowest data value in the parentβs node and merge it with its left sibling.
To delete 99, 99 is present in a leaf node, so the data value can be easily removed.
Now there is a leaf node that has less than 1 data value, thereby violating the property of a 2-3 tree.
So the node must be merged. To merge the node, pull down the lowest data value in the parentβs node and merge it with its left sibling.
To delete 81, 81 is an internal node. To delete this value swap 81 with its in-order successor 90 so that 81 now becomes a leaf node. Remove the value 81 from the leaf node.
Now there is a leaf node that has less than 1 data value, thereby violating the property of a 2-3 tree. So the node must be merged. To merge the node, pull down the lowest data value in the parentβs node and merge it with its left sibling.
As internal node cannot be empty. So now pull down the lowest data value from the parentβs node and merge the empty node with its left sibling
NOTE: In a 2-3 tree, each interior node has either two or three children. This means that a 2-3 tree is not a binary tree.