Download presentation
Presentation is loading. Please wait.
1
CS223 Advanced Data Structures and Algorithms
AVL Tree Neil Tang 02/03/2010 CS223 Advanced Data Structures and Algorithms
2
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
3
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
4
CS223 Advanced Data Structures and Algorithms
Definition CS223 Advanced Data Structures and Algorithms
5
CS223 Advanced Data Structures and Algorithms
Height Upper bound: 1.44log(N+2)-1.328 In practice, slightly more than logN. The complexity of an AVL tree operation is usually O(height). CS223 Advanced Data Structures and Algorithms
6
Cases Causing Violation
Case 1 (left-left): An insertion to the left subtree of the left child of a node. Case 2 (left-right): An insertion to the right subtree of the left child of a node. Case 3 (right-left): An insertion to the left subtree of the right child of a node. Case 4 (right-right): An insertion to the right subtree of the right child of a node. CS223 Advanced Data Structures and Algorithms
7
Single Rotation To Fix Case 1
CS223 Advanced Data Structures and Algorithms
8
Single Rotation To Fix Case 1
CS223 Advanced Data Structures and Algorithms
9
Single Rotation To Fix Case 4
CS223 Advanced Data Structures and Algorithms
10
Single Rotation To Fix Case 4
CS223 Advanced Data Structures and Algorithms
11
Left-Right Double Rotation To Fix Case 2
CS223 Advanced Data Structures and Algorithms
12
Right-Left Double Rotation To Fix Case 3
CS223 Advanced Data Structures and Algorithms
13
Right-Left Double Rotation To Fix Case 3
CS223 Advanced Data Structures and Algorithms
14
CS223 Advanced Data Structures and Algorithms
Right Single Rotation CS223 Advanced Data Structures and Algorithms
15
Left-Right Double Rotation
CS223 Advanced Data Structures and Algorithms
16
Insertion with Rotations
CS223 Advanced Data Structures and Algorithms
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.