SDSU CS 660: Combinatorial Algorithms
AVL TREES

[To Lecture Notes Index]
San Diego State University -- This page last updated October 27, 1995
----------

Contents of AVL TREES Lecture

  1. Height-Balanced Trees
    1. Insertion into a AVL Tree
    2. Insertion into a AVL Tree
    3. Performance

Height-Balanced Trees


Height of a tree is the length of the longest path from the root to a leaf.

A binary search tree T is a height-balanced k-tree or HB[k]-tree, if each node in the tree has the HB[k] property

A node has the HB[k] property if the height of the left and right subtrees of the node differ in height by at most k.

A HB[1] tree is called an AVL tree.

Adel'son-Vel'skii and Landis first defined HB[1] trees

Worst Case AVL Trees


Let = the number of nodes in worst case AVL tree of height n

We have:
Fibonacci Numbers

, ,
n
011
121
242
373
4125
5208
63313

We get

But where

So

Now take any AVL tree of height h with M nodes, we have


M >=


So M + 2 >





h < 1..4404 lg(M + 2) - 0.328

Theorem ( Adel'son-Vel'skii and Landis 1962) The height of a balanced tree with N internal nodes always lies between lg (N +1 ) and 1..4404 lg(M + 2) - 0.328

Insertion into a AVL Tree

Case 1
Add node to subtree 3
Perform Single Rotation

Insertion into a AVL Tree

Case 2
Insert into subtree 2 or 3

Double Rotation

Performance


Theorem. An insertion into an AVL tree requires at most one rotation to rebalance a tree. A deletion may require lg(N) rotations to rebalance the tree.


Simulation Results
nC(n)E[ h(n) ]R(n)
52.23.00.213
102.9074.00.318
504.9306.9470.427
1005.8897.9990.444
5008.19210.9230.461
10009.20211.9980.463
500011.55514.9360.465
1000012.56815.9960.465
n = number of nodes in the tree

C(n) = average number of comparisons to find a key

E[ h(n) ] = expected height of tree

R(n) = average number of rotations per insertion/deletion