Why do insertion and removing operations in 2-3 tree always have complexity of O(logn), is there a mathematical proof?
Asked
Active
Viewed 2,967 times
2
-
I know it's O(logn) and understand why. But I don't understand why removing and insertion operations have the same complexity – Аяз Хуснутдинов May 19 '18 at 18:26
-
But what about split operation when inserting a value to a node? It can be performed all the way up to the root. – Аяз Хуснутдинов May 19 '18 at 18:33
-
I didn't get it :( – Аяз Хуснутдинов May 19 '18 at 18:46
-
You write about subtree below the place I have to insert. But I can insert only in leaves. What subtree are writing about? – Аяз Хуснутдинов May 19 '18 at 19:19
1 Answers
1
- When we insert a key at level
, in the worst case we need to split+ 1nodes (one at each of thelevels plus the root). - A
2-3 treecontainingkeys with the maximum number of levels takes the form of a binary tree where each internal node has one key and two children. - In such a tree
= (2^(+1)) − 1whereis the number of the lowest level. - This implies that
+ 1 = log( + 1)from which we see that the splits are in the worst caselog. - So insertion in a
2-3 treetakes at worsttime. - Similarly we can prove that searches and deletions take
time.
Andrei Suvorkov
- 5,559
- 5
- 22
- 48