3

What is the Big O efficiency of the AVL tree rotation specifically?

For example when inserting: - O(logN) to search for the position - O(1) to insert - ? for balancing (if it needs to be re-balanced)

I thought it would be O(logN) but I found a site which claims it's O(1) - unless I have misread it - http://users.informatik.uni-halle.de/~jopsi/dinf504/chap4.shtml

(Would this also be the same for a 2-3 tree?)

Thanks for the help in advance

GJHix
  • 522
  • 10
  • 18
  • 2
    In your original question you said that insertion is O(1), but insertion is actually also O(log n) even if no re-balancing is required. – NateW Dec 17 '15 at 15:54

1 Answers1

5

The complexity is O(log n) as you say. I believe that in the article they mean constant time for each rebalancing operation i.e. each rotation, while you have to do O(log n) rotations. Whatever the truth the complexity is as you say logarithmic.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176