previous | start | next

Height of an AVL Tree with N Keys

What is an upper bound for the height of an AVL tree with N keys?

This can be determined if we can answer the reverse question:

What is a lower bound for the number of keys in an AVL tree of height h?

Let N be the minimum number of keys that can be in an AVL tree of height h.

Fact
      2h / 2 < N
   

But this means

     h < 2log(N)  
   

Great! The height of an AVL tree is O(log(N)).

Since the height = O(log(N), this means the get method is guaranteed to be O(log(N)) for an AVL tree, even though it isn't perfectly balanced.

The put method first does a search and then either updates a value or else changes a few links to attach a new key value pair. Since the height is O(log(N)), this much would also cost only O(log(N)) for the put method.

However, the put method must also maintain the balance property. So we have make sure that doesn't add any more than O(log(N)) additional steps.



previous | start | next