You are on page 1of 5

Left Rotation (Single Rotation)

The case of single right rotation occur when Insertion of a node takes place
into right sub-tree of right child of any node (lets say node X)
So After the Insert, move toward the root, node by node checking balance
factor at each, because only nodes on the path from insertion point toward
root node have possibly changed in height and have violated balanced
property .
Let the node that needs rebalancing be node X.
BF = -1- (1) = 2

X
Y
Y

Left Rotation

Z
Insert number 4 5 6 7 8 into an empty AVL Tree.

Example

BF = -1 - (1) = -2

4
Insert 4

Insert 5

Insert 6

5
Left Rotation

5
6

Insert 7

5
BF = 2

Left Rotation

7
6

Insert 8

6
7

6
7

Let us take a more complex scenario of Single Left Rotation.


BF = -0 - (2) = -2

Insertion of node Z in the AVL tree leave behind

the tree unbalanced. We can also see from balance

factor of node Z (BF = 2), so single Left rotation


Y

around node B is required to restore its AVL-ness


property of the tree.
Z

Unbalanced Tree

B
A

X
Left Rotation

Example:-

3
BF = 0 - 2 = - 2

Left Rotation

7
6

1
8

5
4

8
6

Single Left Rotation Algorithm

X
Q

Y
Left Rotation

Null

Null

node Single_Left_rotate(node P) //pass node with BF = 2 to this function


{
node Q = P->right;
P->right=Q->left;
Q->left= P;
P = update height;
Q=update height;
return Q;
// return new root node
}

B
Q

X
X

A
C

Left Rotation

Y
Z

Y
C

Example:-

20

20
30

10

10

30

Insert 50
BF = -1-(1) = - 2

35

25

35

25

40

40
Left Rotation

50

20

20
BF = 0 - 2 = -2

30

10

10

30

Insert 60
5

25

40

35

25

50

40

35

50

60
Left Rotation

20

20

20
BF = 2 - 0 = 2

40

10

30
25

50
35

40

10

Insert 2

60

30
25

Right Rotation

50
35

60

40
10

50

30

25

35

60

You might also like