






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







'()'&$$*&++&,-..&$"!"&
'()'&$$*&++&,-..&$"!"& AVL Trees “Self-Balancing” Binary Search Trees Recall that in a BST!
Minimum Height Trees Full and complete binary trees are of “ minimum height ”! 2 h^ – 1 = nodes in a full binary tree !log 2 ( n +1)" = minimum height h of a binary tree! '()'&$$*&++&,-..&$"!"&
Binary Trees A “ balanced ” binary tree has for every node!
h = 3 h = 1 0&
h = 3 h = 2
Binary Trees Are all balanced binary trees of minimum height?!
Heaps Revisited
A “Brute Force” Approach
'()'&$$*&++&,-..&$"!"&
A “Brute Force” Approach
AVL Trees [Adelson-Velskii & Landis, 1962]
a& !P& G& !"& !G& $& P& b = 1 b = 0 b = 1 b = 1
a& !P& G& !"& !G& $& P& !& b = 1 b = 2 b = 2 123456&Q!R& !$& G& !P& $& a& !G& !& P& !"& b = 1 b = 0 b = 1
V?6-b?2& b = 1
AVL Trees
k 2 b = 0 k 1 b = 0 B
AVL Trees
'()'&$$*&++&,-..&$"!"&
AVL Trees A single rotation might not rebalance the tree …! '()'&$$*&++&,-..&$"!"& k 2 b = -1 k 1 b = 2 C
k 2 k 1 b = 1 b = - C
AVL Trees
k 3 b = 0 or 1^ k 2 b = 2 D A B k 1 C b = 1 or 2