Lecture 8 - AVL-Tree 4 slides per page

# Lecture 8 - AVL-Tree 4 slides per page - Readings Best case...

This preview shows pages 1–2. Sign up to view the full content.

1 1 AVL Tree An AVL tree is a balanced binary search tree. Named after its inventors A del’son- V el’skii and L andis 2 Readings ± Required ² 3 Outline ± right rotation, left rotation ± AVL tree property ± height of AVL tree ± AVL tree node insertion ² single rotation ² double rotation ± STL set, multiset, map, multimap 4 Previously, on BST ± findMin O(h) where h = height of the tree ± search O(h) ± insert O(h) ± delete O(h) But h is not always O(log 2 N)! 2 5 Best case, worst case Best case worst case 6 Rotation 2 1 5 3 6 2 1 5 3 6 The skewed tree can be converted into the “ balanced ”tree through a series of rotations . 7 Rotate Right at 3 5 4 8 7 1 3 9 2 6 0 8 After Rotate Right at 3 (cont.) 5 4 8 7 1 3 9 2 6 0 Rotation changes the heights of some nodes. The depths of nodes 3 and 4 increase by 1. The depths of nodes 0 and 1 decreases by 1. The depth of node 2 remains unchanged 3 9 After Rotate Right at 3 (cont.) 5 4 8 7 1 3 9 2 6 0 Rotation modifies the pointers shown in red . 10 Rotate Right at 3 (cont.) rotateRight(x) l = x.left if l is empty return x.left = l.right l.right = x p = x.parent if x is a left child p.left= l else p.right = l 5 4 1 3 2 0 l p x The pseudo code on the right shows how we rotate right at x. The

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

Lecture 8 - AVL-Tree 4 slides per page - Readings Best case...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online