AVL Trees And the pain you must suffer to learn them
The AVL Property For every node the left and right side differ in height by less than two. The left and right side are themselves AVL trees.
How Balanced is That? AVL trees might end up kinda 'sparse'. The worst case height of an AVL tree with n nodes is about 1.44log(n). Discussion at LDS210/AVL.html LDS210/AVL.html
Rotations Rotations are to rearrange nodes to maintain AVLness. They are needed on insert and delete.
Names of Rotations There are four of them –Single Left (LL) and Single Right (RR) –Double Left (LR) and Double Right (RL) The names describe which way the node moves. For example, a left rotation moves the node down and left. Nodes always move down when rotated.
How To Do Single Rotations
A Left Rotation via Pointers temp=p->right ; p->right=temp->left ; temp->left=p ; p=temp ;
Double Rotation A LR double rotation is to rotate something to the left, and then its former parent to the right. A RL double rotation is to rotate something to the right, and then its former parent to the left.
Rotation Examples All the rotations in picture form ree.html ree.html All the rotations in pictures and text oils/balancedTrees/balancedTrees.html oils/balancedTrees/balancedTrees.html Sample single and double rotations ubjects/DataStructures/mal/session200/lecture.h tml ubjects/DataStructures/mal/session200/lecture.h tml
The AVL Insertion Algorithm An Intuitive description can be found at Comp175/notes/avlTrees.html Comp175/notes/avlTrees.html
The AVL Game Play the game