









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of balanced trees, specifically avl trees. Avl trees are a self-balancing binary search tree where the height differences between the left and right subtrees of each node are kept minimal. The properties of avl trees, the insertion process, and the cases where rotations are required to maintain balance. It also mentions the advantages and disadvantages of avl trees compared to other self-balancing tree structures like splay trees.
Typology: Study notes
1 / 17
This page cannot be seen from the preview
Don't miss anything!










u height (LEFT(u)) left_height (u) right_height defined analogously balance (u) := right_height (u) - left_height (u) Positive when right subtree is taller than left subtree 0 when the trees are the same height Negative when left subtree is taller than right subtree
0 +
- balance (u) := right_height (u) - left_height (u) 0 0 0 0 0 0 (^0 ) 0 +1 (^0 ) **-
-2** (^0) - NOT an AVL tree
u
0 0 -**
u
n h h- -1 → 0 u n h h 0 → + Node was added to the shorter subtree Subtrees were equal, now slightly unbalanced The symmetric cases (when left subtree was shorter, e.g.) are handled the same way.
u n h i
- h h Too tall! Too short! u n h i h h Right rotation (aka clockwise rotation) 0 0 - Why does obey BST ordering?
n i n i Left rotation (aka counterclockwise rotation) Only a constant # of pointers need to be updated for a rotation: O(1) time
0 -** critical node
n h i h h 0 0 n h i
- h (^) h - height = h + height = h + n h+ i - k h h - h+ + n h+ i k h h h+ 0 + height = h +3 height = h +3 0 Left, Left Case: Left, Right Case:
Worst case O(log _n_ ) performance guarantee Have to maintain extra balance factor storage at each node. remove extra storage requirement, Without knowing how splay is implemented, we can implement our usual operations as follows: j j k