0% found this document useful (0 votes)
18 views94 pages

Lecture 20 - AVL Trees

AVL Trees are a type of self-balancing binary search tree where the difference in heights between the left and right sub-trees is at most 1. To maintain balance after insertions, rotations (single or double) are performed based on the balance factors of the nodes. The document provides examples and explanations of how to construct and maintain AVL trees through various insertion scenarios and balancing techniques.

Uploaded by

i220894
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views94 pages

Lecture 20 - AVL Trees

AVL Trees are a type of self-balancing binary search tree where the difference in heights between the left and right sub-trees is at most 1. To maintain balance after insertions, rotations (single or double) are performed based on the balance factors of the nodes. The document provides examples and explanations of how to construct and maintain AVL trees through various insertion scenarios and balancing techniques.

Uploaded by

i220894
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 94

Data Structures

20. AVL Trees

20-AVL 1
Balanced and Unbalanced BST

1 4
2 2 5
3
1 3
4
4 Is this “balanced”?
5
2 6 6

1 3 5 7 7

20-AVL 2
Balanced Tree

• Want a (almost) complete tree after every operation


– Tree is complete except possibly in the lower levels towards right

• Maintenance of such a tree is expensive


– For example, insert 2 in the tree on the left and then rebuild as a
complete tree

6 5
Insert 2 &
4 9 complete tree 2 8

1 5 8 1 4 6 9

20-AVL 3
AVL Trees – Good but not Perfect Balance

• Named after Adelson-Velskii and Landis

• Balance is defined by comparing the height of the two sub-trees

• Recall:
– An empty tree has height –1
– A tree with a single node has height 0

20-AVL 4
AVL Trees

• A binary search tree is said to be AVL balanced if:


– The difference in the heights between the left and right sub-trees is at
most 1, and
– Both sub-trees are themselves AVL trees

• AVL trees with 1, 2, 3 and 4 nodes

20-AVL 5
AVL Trees – Example

5 7

2 8 2 8

1 4 7 1 4

3 3 5

An AVL Tree Not an AVL Tree


20-AVL 6
AVL Trees – Balance Factor

• An AVL tree has balance factor calculated at every node


– Height of the left subtree minus the height of the right subtree
– For an AVL tree, the balances of the nodes are always -1, 0 or 1

Height of node =h
Balance Factor (BF) = hleft - hright
Empty height = -1
Tree A (AVL) Tree B (AVL)
height=2 BF=1-0=1
1
6 6
4 9 0 4 9
0 0
1 5 -1 -1 1 5 8 -1

-1 -1 -1 -1 20-AVL -1 -1 -1 -1 -1 -1 7
AVL Trees – Example

Tree A (AVL) Tree B (not AVL)


3 balance factor
1-(-1) = 2
6 6
2
4 9 4 9
1 -1
1 5 7 1 5 8
0
7
Height of node = h
Balance factor = hleft-hright
Empty height = -1

20-AVL 8
AVL Trees – Example

• Consider this AVL tree

20-AVL 12
AVL Trees – Example

• Consider inserting 15 into this tree


– In this case, the heights of none of the trees change
– Tree remains balanced

20-AVL 13
AVL Trees – Example

• Consider inserting 42 into this tree

20-AVL 14
AVL Trees – Example

• Consider inserting 42 into this tree


– Height of two sub-trees rooted at 44 and 38 have increased by one
– The tree is still balanced

20-AVL 15
AVL Trees

• To maintain the height balanced property of the AVL tree, it is


necessary to

– Perform a transformation on the tree, such that

– In-order traversal of the transformed tree is the same as for the


original tree (i.e., the new tree remains a binary search tree)

20-AVL 17
Transformation (Rotation) of AVL Trees

• Insert operations may cause balance factor to become 2 or –2 for


some node

• Only nodes on the path from insertion point to root node have
possibly change in height

• Follow the path up to the root, find the first node (i.e., deepest)
whose new balance violates the AVL condition
– Call this node “a”

• If a new balance factor (the difference hleft-hright) is 2 or –2


– Adjust tree by rotation around the node “a”

20-AVL 18
Balancing AVL Trees – Example

• If a tree is AVL balanced, for an insertion to cause an imbalance:


– The heights of the sub-trees must differ by 1
– The insertion must increase the height of the deeper sub-tree by 1

20-AVL 19
Balancing AVL Trees – Example

• Suppose we insert 23 into our initial tree

20-AVL 20
Balancing AVL Trees – Example

• The heights of each of the sub-trees from the insertion point to the
root are increased by one

20-AVL 21
Balancing AVL Trees – Example

• Only two of the nodes are unbalanced, i.e., 17 and 36


– Balance factor of 17 is -2
– Balance factor of 36 is 2

20-AVL 22
Balancing AVL Trees – Example

• We only have to fix the imbalance at the lowest node

20-AVL 23
Fixing Imbalance By Rotation

• Let the node that needs rebalancing be “a”


• Imbalance during insertion may be handled using four cases

• Outside cases (Single Rotation)


1. Right rotation (case RR)
2. Left rotation (case LL)

• Inside cases (Double Rotation)


3. Right-left rotation (case RL)
4. Left-right rotation (case LR)

20-AVL 24
Single Rotation in an AVL Tree

2 2
6 6
1 2 1
1
4 9 4 8
0 0 1 0 0 0 0
1 5 8 1 5 7 9
0
7

20-AVL 25
Right Rotation (RR) in an AVL Tree

a
b
b
c a
c

• Node “b” becomes the new root


• Node “b” takes ownership of node “a”, as it's right child
• Node “a” takes ownership of node “b” right child (NULL if no child)
– As left child of node “a”

20-AVL 26
Right Rotation (RR) – Example

• Consider adding 6

20-AVL 27
Right Rotation (RR) – Example

• Height of each of the trees in the path back to the root are
increased by one

20-AVL 28
Right Rotation (RR) – Example

• Height of each of the trees in the path back to the root are
increased by one
– Only root node (i.e., 36) violates the balancing factor

20-AVL 29
Right Rotation (RR) – Example

• To fix the imbalance, we perform right rotation of root (i.e., 36)

17 27

20-AVL 30
When to Perform Right Rotation (RR)?

• Let the node that needs rebalancing be “a”

• Case RR
– Insertion into left subtree of left child of node “a”
– Left tree is heavy (i.e., hleft > hright )

20-AVL 31
When to Perform Right Rotation (RR)

• Let the node that needs rebalancing be a

• Case RR
– Insertion into left subtree of left child of node a (RR)
– Left tree is heavy (i.e., hleft > hright )

20-AVL 32
Right Rotation (RR) – Examples

20-AVL 33
Left Rotation (LL) in an AVL Tree

a
b
b
a c
c

• Node “b” becomes the new root


• Node “b” takes ownership of node “a” as its left child
• Node “a” takes ownership of node “b” left child (NULL if no child)
– As right child of node “a”

20-AVL 34
Left Rotation (LL) – Example

• Consider adding 67
– To fix the imbalance, we perform left rotation of root (i.e., 36)

20-AVL 35
When to Perform Left Rotation (LL)

• Let the node that needs rebalancing be “a”

• Case LL
– Insertion into right subtree of right child of node a
– Right tree is heavy (i.e., hleft < hright )

20-AVL 36
When to Perform Left Rotation (LL)

• Let the node that needs rebalancing be a

• Case LL
– Insertion into right subtree of right child of node a (LL)
– Right tree is heavy (i.e., hleft < hright )

20-AVL 37
Single Rotation May Be Insufficient

• The imbalance is just


shifted to the other
side

20-AVL 38
Right-Left Rotation (RL) or "Double Right"

c c
b
a b
Right
a c
b Left
a

• Perform a left rotation on the • Node “b” becomes the new


left subtree root
• Node “b” takes ownership of
node “c” as its right child
• Node “c” takes ownership of
node “b” right child
– As its left child
20-AVL 39
Right-Left Rotation (RL) or "Double Right" – Example

20-AVL 40
When to Perform Right-Left Rotation (RL)

• Let the node that needs rebalancing be “a”

• Case RL
– Insertion into right subtree of left child of node “a”

20-AVL 41
When to Perform Right-Left Rotation (RL)

• Let the node that needs rebalancing be a

• Case RL
– Insertion into right subtree of left child of node a (RL)

Left heavy

Right heavy

20-AVL 42
Left-Right Rotation (LR) or "Double Left"

a a
b
c b Left
a c
b Right c

• Perform a right rotation on • Node “b” becomes the new


the right subtree root
• Node “b” takes ownership of
node “a” as its left child
• Node “a” takes ownership of
node “b” left child
– As its right child

20-AVL 43
Left-Right Rotation (LR) or "Double Left" – Example

• Consider adding 67
– To fix the imbalance, we perform left-right (LR) rotation of root

20-AVL 44
When to Perform Left-Right Rotation (LR)

• Let the node that needs rebalancing be a

• Case LR
– Insertion into left subtree of right child of node a

20-AVL 45
When to Perform Left-Right Rotation (LR)

• Let the node that needs rebalancing be a

• Case LR
– Insertion into left subtree of right child of node a (LR)

Right heavy

Left heavy

20-AVL 46
Summary: How And When To Rotate?

• Let the node that needs rebalancing be “a”


• Violation during insertion may occur in four cases

• Outside cases (Single Rotation)


1. Insertion into left subtree of
left child of node a (case RR)
Case 1: RR

2. Insertion into right subtree of


right child of node a (case LL)

Case 2: LL
20-AVL 47
Summary: How And When To Rotate?

• Let the node that needs rebalancing be “a”


• Violation during insertion may occur in four cases

• Inside cases (Double Rotation)


3. Insertion into right subtree of
left child of a (case RL)

Case 3: RL
4. Insertion into left subtree of
right child of a (case LR)

Case 4: LR
20-AVL 48
Summary: How And When To Rotate?
if tree is right heavy {
if tree's right subtree is left heavy {
Perform Left-Right rotation
}
else {
Perform Single Left rotation
}
}


else if tree is left heavy {
if tree's left subtree is right heavy {
Perform Right-Left rotation
}
else {
Perform Single Right rotation
}
}
20-AVL 49
AVL Tree – Complete Example

• Construct AVL Tree with the following input elements


– 3, 2, 1, 4, 5, 6, 7
Insert 3, 2, 1

Insert 4, 5

20-AVL 50
AVL Tree – Complete Example

• Construct AVL Tree with the following input elements


– 3, 2, 1, 4, 5, 6, 7
Insert 4, 5

Insert 6

20-AVL 51
AVL Tree – Complete Example

• Construct AVL Tree with the following input elements


– 3, 2, 1, 4, 5, 6, 7
Insert 6

Insert 7

20-AVL 52
AVL Tree – Complete Example

• Construct AVL Tree with the following input elements


– 3, 2, 1, 4, 5, 6, 7
Insert 7

20-AVL 53
AVL Tree – Complete Example

• Suppose the following elements have to be inserted further


– 16, 15, 14, 13, 12, 11, 10, 8
Insert 16, 15

Insert 14
20-AVL 54
AVL Tree – Complete Example

• Suppose the following elements have to be inserted further


– 16, 15, 14, 13, 12, 11, 10, 8
Insert 14

Insert 13
20-AVL 55
AVL Tree – Complete Example

• Suppose the following elements have to be inserted further


– 16, 15, 14, 13, 12, 11, 10, 8
Insert 13

Insert 12
20-AVL 56
AVL Tree – Complete Example

• Suppose the following elements have to be inserted further


– 16, 15, 14, 13, 12, 11, 10, 8
Insert 12

Insert 11, 10
20-AVL 57
AVL Tree – Complete Example

• Suppose the following elements have to be inserted further


– 16, 15, 14, 13, 12, 11, 10, 8
Insert 11, 10 then 8

20-AVL 58
AVL Tree Implementation

20-AVL 59
AVL Trees: Implementation
struct AvlNode {
ElementType Element;
AvlTree Left;
AvlTree Right;
int Height;
};
typedef struct AvlNode *Position;
typedef struct AvlNode *AvlTree;
AvlTree MakeEmpty( AvlTree T );
Position Find( ElementType X, AvlTree T );
Position FindMin( AvlTree T );
Position FindMax( AvlTree T );
AvlTree Insert( ElementType X, AvlTree T );
AvlTree Delete( ElementType X, AvlTree T );
ElementType Retrieve( Position P );

20-AVL 60
AVL Trees: Implementation
int Height(Position P )
{
if( P == NULL )
return -1;
else
return P->Height;
}

20-AVL 61
AVL Trees: Insert Function
AvlTree Insert( ElementType X, AvlTree T ) {
if ( T == NULL ) { /* Create and return a one-node tree */
T = new AvlNode;
T->Element = X;
T->Left = T->Right = NULL;
}
else if( X < T->Element ) {
T->Left = Insert( X, T->Left );
if( Height( T->Left ) - Height( T->Right ) == 2 )
if( X < T->Left->Element )
T = SingleRotateWithLeft( T ); // RR rotation
else
T = DoubleRotateWithLeft( T ); // RL rotation
}
else if( X > T->Element ) {
T->Right = Insert( X, T->Right );
if( Height( T->Right ) - Height( T->Left ) == 2 )
if( X > T->Right->Element )
T = SingleRotateWithRight( T ); // LL rotation
else
T = DoubleRotateWithRight( T ); // LR rotation
} /* Else X is in the tree already; we'll do nothing */
T->Height = Max( Height( T->Left ), Height( T->Right ) ) + 1;
return T;
} 20-AVL 62
AVL Trees: Insert Function
AvlTree Insert( ElementType X, AvlTree T ) {
if ( T == NULL ) { /* Create and return a one-node tree */
T = new AvlNode;
T->Element = X;
T->Left = T->Right = NULL;
}
else if( X < T->Element ) {
T->Left = Insert( X, T->Left );
if( Height( T->Left ) - Height( T->Right ) == 2 )
if( X < T->Left->Element )
T = SingleRotateWithLeft( T ); // RR rotation
else
if ( TT == NULL ) { /* Create
= DoubleRotateWithLeft( T ); // and return a
RL rotation one-node tree */
} T = new AvlNode;
else T->Element = )X;{
if( X > T->Element
T->Right = Insert( X, T->Right );
T->Left = T->Right = NULL;
if( Height( T->Right ) - Height( T->Left ) == 2 )
} if( X > T->Right->Element )
T = SingleRotateWithRight( T ); // LL rotation
else
T = DoubleRotateWithRight( T ); // LR rotation
} /* Else X is in the tree already; we'll do nothing */
T->Height = Max( Height( T->Left ), Height( T->Right ) ) + 1;
return T;
} 20-AVL 63
AVL Trees: Insert Function
AvlTree Insert( ElementType X, AvlTree T ) {
if ( T == NULL ) { /* Create and return a one-node tree */
T = new AvlNode;
T->Element = X;
T->Left = T->Right = NULL;
}
else if( X < T->Element ) {
T->Left = Insert( X, T->Left );
if( Height( T->Left ) - Height( T->Right ) == 2 )
if( X < T->Left->Element )
T = SingleRotateWithLeft( T ); // RR rotation
else
T = DoubleRotateWithLeft( T ); // RL rotation
}
else if( X > T->Element ) {
else if( = XInsert(
T->Right < T->Element
X, T->Right );) {
T->Left
if( = Insert(
Height( T->Right X, T->Left
) - Height( T->Left ) ==);
2 )
if( X > T->Right->Element )
if( Height( T->Left ) - Height( T->Right ) == 2 )
T = SingleRotateWithRight( T ); // LL rotation
if( X < T->Left->Element )
else
T = SingleRotateWithLeft(
T = DoubleRotateWithRight( T ); //
T ); // LR rotation RR rotation
} /* Else else
X is in the tree already; we'll do nothing */
T->Height = Max( Height( T->Left ), Height( T->Right ) ) + 1;
T = DoubleRotateWithLeft( T ); // RL rotation
return T;
}
} 18-AVL 64
AVL Trees: Insert Function
AvlTree Insert( ElementType X, AvlTree T ) {
if ( T == NULL ) { /* Create and return a one-node tree */
else if( X > T->Element ) {
T = new AvlNode;
T->Right
T->Element = X; = Insert( X, T->Right );
if( =Height(
T->Left T->Right = T->Right
NULL; ) - Height( T->Left ) == 2 )
} if( X > T->Right->Element )
else if( X < T->Element ) {
T = SingleRotateWithRight( T ); // LL rotation
T->Left = Insert( X, T->Left );
elseT->Left ) - Height( T->Right ) == 2 )
if( Height(
T = DoubleRotateWithRight(
if( X < T->Left->Element ) T ); // LR rotation
} T = SingleRotateWithLeft( T );
else
/* Else X is in the tree already; we'll do nothing */
T = DoubleRotateWithLeft( T );
}
else if( X > T->Element ) {
T->Right = Insert( X, T->Right );
if( Height( T->Right ) - Height( T->Left ) == 2 )
if( X > T->Right->Element )
T = SingleRotateWithRight( T ); // LL rotation
else
T = DoubleRotateWithRight( T ); // LR rotation
} /* Else X is in the tree already; we'll do nothing */
T->Height = Max( Height( T->Left ), Height( T->Right ) ) + 1;
return T;
} 20-AVL 65
AVL Trees: Insert Function
AvlTree Insert( ElementType X, AvlTree T ) {
if ( T == NULL ) { /* Create and return a one-node tree */
T = new AvlNode;
T->Element = X;
T->Left = T->Right = NULL;
}
else if( X < T->Element ) {
T->Left = Insert( X, T->Left );
if( Height( T->Left ) - Height( T->Right ) == 2 )
if( X < T->Left->Element )
T = SingleRotateWithLeft( T ); // RR rotation
else
T = DoubleRotateWithLeft( T ); // RL rotation
}
else if( X > T->Element ) {
T->Right = Insert( X, T->Right );
if( Height( T->Right ) - Height( T->Left ) == 2 )
if( X > T->Right->Element )
T->Height = Max( Height( T->Left ), Height(
T = SingleRotateWithRight( T ); // LL rotation
T->Right ) ) + 1;
returnelseT;
T = DoubleRotateWithRight( T ); // LR rotation
} /* Else X is in the tree already; we'll do nothing */
T->Height = Max( Height( T->Left ), Height( T->Right ) ) + 1;
return T;
} 20-AVL 66
AVL Trees: LL Rotation
Position SingleRotateWithRight( Position K1 ) {
Position K2;
K2 = K1->Right; // K1: node whose balance factor is violated
K1->Right = K2->Left;
K2->Left = K1;
K1->Height = Max( Height(K1->Left), Height(K1->Right) ) + 1;
K2->Height = Max( Height(K2->Right), K1->Height ) + 1;
return K2; /* New root */
}
K1 K2
20
K2 40
Left Rotation
K1
10 40
20 50
30 50
10 30 60
60
20-AVL 67
AVL Trees: RR Rotation
Position SingleRotateWithLeft( Position K1 ) {
Position K2;
K2 = K1->Left; // K1: node whose balance factor is violated
K1->Left = K2->Right;
K2->Right = K1;
K1->Height = Max( Height(K1->Left), Height(K1->Right) ) + 1;
K2->Height = Max( Height(K2->Left), K1->Height ) + 1;
return K2; /* New root */
}

20-AVL 68
AVL Trees: LR Rotation
Position DoubleRotateWithRight( Position K1)
{
/* RR rotation between K3 and K2 */
K1->Right = SingleRotateWithLeft( K1->Right );
/* LL rotation between K1 and K2 */
return SingleRotateWithRight( K1 );
} Single Right Rotation at K3
Single Left rotation at K1

20-AVL 69
LR Rotation

• Adding node 22
– Requires double rotation!

40 40

20 50 20 50

10 30 60 10 30 60

25 35 25 35

22

20-AVL 70
LR Rotation

40 40
K1 K1
20 50 20 50
K3 K2
10 30 60 10 25 60
K2 K3
25 35 22 30

22
35

20-AVL 71
LR Rotation

40 40
K1 K2
20 50 25 50
K2 K1 K3
10 25 60 20 30 60

K3
22 30 10 22 35

35

20-AVL 72
AVL Trees: RL Rotation
Position DoubleRotateWithLeft( Position K3 )
{
/* LL rotation between K1 and K2 */
K3->Left = SingleRotateWithRight( K3->Left );
/* RR rotation between K3 and K2 */
return SingleRotateWithLeft( K3 );
}
Single Left Rotation at K1
Single Right rotation at K3

20-AVL 73
AVL Tree Deletion

20-AVL 74
AVL Tree: Deletion

• Goal: To preserve the height balance property of BST after deletion

• Step 1: Perform BST delete


– Maintains the BST property
– May break the balance factors of ancestors!

• Step 2: Fix the AVL tree balance constraint


– Perform transformation on the tree by means of rotation such that
 BST property is maintained
 Transformation fixes any balance factors that are < -1 or > 1

20-AVL 75
AVL Tree: Deletion

• BST deletion breaks the invarialants of AVL tree

7 7

Delete(9)
4 9 4

3 3

NOT an AVL tree!

20-AVL 76
AVL Tree: Deletion

• BST deletion breaks the balance factors of incestors

1 7 0 1 7

Delete(3)
1 4 0 9 01 4 0 9

0 3

20-AVL 77
AVL Tree: BST Deletion

• Case 1: Node to be deleted has degree 0 (i.e., leaf node)


– Consider deleting node containing 62

• Action position: Reference to parent node from which a node has


been physically removed
– First node whose height may be changed by deletion
20-AVL 78
AVL Tree: BST Deletion

• Case 2: Node to be deleted has degree 1 (i.e., node with one child)
– Consider deleting node containing 84

20-AVL 79
AVL Tree: BST Deletion

• Case 3: Node p to be deleted has two children (i.e., degree 2)


– Replace node p with the minimum object in the right subtree
– Delete that object from the right subtree
– Consider deleting node containing 78

20-AVL 80
AVL Tree: BST Deletion

• Case 3: Node p to be deleted has two children (i.e., degree 2)


– Replace node p with the minimum object in the right subtree
– Delete that object from the right subtree
– Consider deleting node containing 78

20-AVL 81
AVL Tree Deletion

• After removing a child, delete must check for imbalance


– Similar to insert operation

• Rotations can be used to re-balance an out-of-balanced AVL tree


– LL, RR, LR and RL rotations

20-AVL 82
AVL Tree Deletion: Example

• Deleting a node from an ALV tree can cause imbalance


– Consider deleting node 32

20-AVL 83
AVL Tree Deletion: Example

• The balance factor changes at only nodes between the root and
the parent node of the physically deleted node
– Starting at the action position find the first imbalanced node

20-AVL 84
AVL Tree Deletion: Example

• Perform rotation using shaded nodes


– Node a is the first imbalanced node from the action position
– Node c is the child node of node a that has the higher height
– Node b is the child node of node b that has the higher height

c
b

20-AVL 85
AVL Tree Deletion: Example

• The tree after LR rotation

20-AVL 86
AVL Tree Deletion: Multiple Imbalance

• The imbalance at the first imbalance node due to a deletion


operation can be restored using rotation
– Resulting subtree does not have the same height as the original
subtree !!!
– Nodes that are further up the tree may require re-balancing

• Deleting a node may cause more than one AVL imbalance !!!

• Unfortunately, delete may cause O(h) imbalances


– Insertions will only cause one imbalance that must be fixed

20-AVL 87
AVL Tree Deletion: Example

• Consider the following AVL tree

Original height of the subtree


rooted at 75 is 2

20-AVL 88
AVL Tree Deletion: Example

• Node with value 80 is deleted


– The imbalance is on left-left subtree
– Imbalance can be fixed using RR rotation

20-AVL 89
AVL Tree Deletion: Example

• Node 50 requires re-balancing


– The imbalance is on left-left subtree
– Imbalance can be fixed using RR rotation – Home work!!

Resultant height of the


subtree is 1

20-AVL 90
AVL Tree Deletion: Example

• Consider the following AVL tree


– Suppose node with value 1 is deleted

20-AVL 91
AVL Tree Deletion: Example

• While its previous parent, 2, is not unbalanced, its grandparent 3 is


– The imbalance is in the right-right subtree

20-AVL 92
AVL Tree Deletion: Example

• While its previous parent, 2, is not unbalanced, its grandparent 3 is


– The imbalance is in the right-right subtree
– Imbalance can be fixed using LL rotation

20-AVL 93
AVL Tree Deletion: Example

• The subtrees of node 5 is now balanced


• Recursing to the root, however, 8 is also unbalanced
– The imbalance is in right-left subtree

20-AVL 94
AVL Tree Deletion: Example

• The node with value 8 is unbalanced


– The imbalance is in right-left subtree
– LR rotation can fix imbalance

20-AVL 95
AVL Tree Deletion: Example

• Root 21 is still imbalanced


– The imbalance is in right-right subtree

20-AVL 96
AVL Tree Deletion: Example

• Root 21 is still imbalanced


– The imbalance is in right-right subtree
– LL rotation can fix the imbalance

20-AVL 97
Any Question So Far?

20-AVL 98

You might also like