AVL trees Removal Height February 13 2019 Cinda
AVL trees Removal Height February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 1
AVL removal • AVL properties must be satisfied before and after removal • Begin with basic BST removal (using predecessor data replacement) – local root balance is adjusted for removing from left or right subtree – maintain a decrease variable (analogous to increase in insertion) to indicate whether the height of the subtree decreased – use the decrease variable to increment or decrement local root balance – rebalance if critical February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 2
AVL tree removal example 1 47 32 71 25 39 35 65 87 53 82 93 77 February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 3
AVL tree removal example 1 Remove 65 47 32 71 25 39 35 65 87 53 82 93 77 Attach child to parent February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 4
AVL tree removal example 1 Remove 65 47 32 71 RL imbalance 25 39 53 OK 87 82 35 93 77 February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 5
AVL tree removal example 1 Remove 65 47 OK 32 82 25 39 35 71 52 OK 87 77 93 Done February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 6
AVL tree removal example 2 Remove 47 39 47 32 71 25 39 35 65 87 53 82 93 77 Replace data with predecessor's data Remove predecessor February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 7
AVL tree removal example 2 Remove 47 39 RR imbalance 32 OK 25 71 35 65 87 53 82 93 77 February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 8
AVL tree removal example 2 Remove 47 71 OK 39 87 32 25 65 35 53 82 93 77 Done February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 9
AVL tree removal example 3 Remove 25 47 32 71 25 39 35 65 87 53 82 93 77 Remove node February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 10
AVL tree removal example 3 Remove 25 47 RL imbalance 32 71 39 35 65 87 53 82 93 77 February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 11
AVL tree removal example 3 Remove 25 47 RR imbalance 35 32 71 39 65 87 53 82 93 77 February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 12
AVL tree removal example 3 Remove 25 71 47 87 35 32 65 39 53 82 93 77 Done February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 13
AVL tree height • February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 14
AVL tree height • 1 Nh-1 February 13, 2019 Nh-2 Cinda Heeren / Will Evans / Geoffrey Tien 15
AVL tree height • February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 16
Readings for this lesson • Carrano & Henry – Chapter 19. 5 (AVL trees) • Next class: – Carrano & Henry, Chapter 18. 4. 1 (Hash functions) February 13, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 17
- Slides: 17