The insertion complexity of RBT and BST are O(logn). I've implemented both of them in Java and give them a lot of numbers and measured the time in seconds to analyze the performance.The numbers I have plotted seem to show that it is O(n). Can anyone think on this and comment why this is the case?
Asked
Active
Viewed 354 times
1 Answers
0
It is possible for BST to have O (n) insertion time, for example if you are inserting elements in increasing or decreasing order.
It is also possible for RBT to have O (n) insertion time, because the tree needs additional time for rebalancing.
O (log n) is the average complexity for insertion (not worst-case).

mangusta
- 3,470
- 5
- 24
- 47