CSE 3358 NOTE SET 13 Data Structures and Algorithms
Tree Balancing - AVL Self-balancing binary search tree The height of the left and right subtrees of every node differ by at most one Based on Balance Factor – the height of the right subtree minus the height of the left subtree. For AVL tree, all balance factors must be +1, 0,
AVL - Operations Searching – close to O(lg n) Insert – may have to update balance property all the way up the tree because it could cause a violation of the AVL property Insert 6.
4 Cases For a particular node, there are 4 possible insertion places. NNNN Case 1Case 2Case 3Case 4 Case 1 and Case 4 – Single Rotation Case 2 and Case 3 – Double Rotation
AVL Case 1 P Q AB C Original Tree Insert node in Subtree A P Q A B C Single Rotation: Rotate Q about P P Q A BC 1 2
AVL Case 4 Original Tree Insert node in Subtree c Single Rotation: Rotate P about Q Q P BC 1 2 A Q P B C A Q P B C A
Example : 3,2,1,4,5,6,7
?