Professional Documents
Culture Documents
Right Left Rotation PDF
Right Left Rotation PDF
The situation of Right-Left Rotation will arise when we insert a node in the
AVL Tree as given below: Insertion of node Y cause the balance factor node Z to
X
Right Rotation
at node Z
Left Rotation
at node X
X
Z
X
Z
Y
NULL
Right Rotation
at Node Z
X
Left Rotation
at Node X
Y
NULL
X
Z
Example
30
30
Right Rotation
40
35
35
Left Rotation
35
30
40
35
Insert 45
40
30
40
45
Insert 42
35
35
35
Left Rotation
42
2
30
30
40
30
40
Right Rotation
40
42
45
45
45
42
Insert 41
35
35
30
42
40
Right Rotation
45
41
30
40
40
Left Rotation
42
35
42
30
41
45
Right Left Rotation
41
45
A
X
C
Unbalanced Tree
B
A
Right Rotation
at Node Y
Left Rotation
at Node B
OR
B
B
A
Y
C
Right Rotation
at Node Y
C
Left Rotation
at Node B
C
Y
A
X
Z
Right Left Rotation
P
Perform right
rotation around Z
X
Y
P->right
Right Rotation
Left Rotation
Y
Null
node double_right_left_rotate(node P)
{
node Q;
P->right = single_right_rotate(p->right);
Q = single_left_rotate(P);
return Q;
Perform right
rotation around Y
Perform right
rotation around B
P->right
Y
X
Left Rotation
X
C
Right Rotation
Y
A
Z
Right Left Rotation
Example:BF = 2
20
30
20
40
10
Insert 35
10
40
30
50
30
20
Right-Left Rotation
40
10
50
35
30
30
30
50
35
BF = 2
20
40
Right-Left Rotation
40
20
Insert 23
40
20
BF = 2
35
25
10
22
10
50
29
22
10
50
35
25
22
35
50
29
29
25
23
Right-Left Rotation
30
25
30
Right-Left Rotation
BF = 2
40
22
20
10
35
25
23
28
50
20
10
22
40
22
Insert 27
35
25
23
28
27
20
50
10
30
28
23
27
40
35
50