CS223 Advanced Data Structures and Algorithms AVL Tree Neil Tang 02/05/2008 CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Class Overview Definition Tree height Tree rotation: single and double Insertion with rotations CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Definition An AVL tree is a special binary search tree in which for each node, the heights of its left and right subtree can differ by at most 1. CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Height Upper bound: 1.44log(N+2)-1.328 In practice, slightly more than logN. CS223 Advanced Data Structures and Algorithms
Cases Causing Violation An insertion to the left subtree of the left child of a node. An insertion to the right subtree of the left child of a node. An insertion to the left subtree of the right child of a node. An insertion to the right subtree of the right child of a node. CS223 Advanced Data Structures and Algorithms
Single Rotation To Fix Case 1 CS223 Advanced Data Structures and Algorithms
Single Rotation To Fix Case 1 CS223 Advanced Data Structures and Algorithms
Single Rotation To Fix Case 4 CS223 Advanced Data Structures and Algorithms
Single Rotation To Fix Case 4 CS223 Advanced Data Structures and Algorithms
Left-Right Double Rotation To Fix Case 2 CS223 Advanced Data Structures and Algorithms
Right-Left Double Rotation To Fix Case 3 CS223 Advanced Data Structures and Algorithms
Right-Left Double Rotation To Fix Case 3 CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Left Single Rotation CS223 Advanced Data Structures and Algorithms
Left-Right Double Rotation CS223 Advanced Data Structures and Algorithms
Insertion with Rotations CS223 Advanced Data Structures and Algorithms