Download presentation
Presentation is loading. Please wait.
1
CS223 Advanced Data Structures and Algorithms
AVL Tree Neil Tang 02/05/2008 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
Height Upper bound: 1.44log(N+2)-1.328 In practice, slightly more than logN. CS223 Advanced Data Structures and Algorithms
5
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
6
Single Rotation To Fix Case 1
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 4
CS223 Advanced Data Structures and Algorithms
9
Single Rotation To Fix Case 4
CS223 Advanced Data Structures and Algorithms
10
Left-Right Double Rotation To Fix Case 2
CS223 Advanced Data Structures and Algorithms
11
Right-Left Double Rotation To Fix Case 3
CS223 Advanced Data Structures and Algorithms
12
Right-Left Double Rotation To Fix Case 3
CS223 Advanced Data Structures and Algorithms
13
CS223 Advanced Data Structures and Algorithms
Left Single Rotation CS223 Advanced Data Structures and Algorithms
14
Left-Right Double Rotation
CS223 Advanced Data Structures and Algorithms
15
Insertion with Rotations
CS223 Advanced Data Structures and Algorithms
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.