Академический Документы
Профессиональный Документы
Культура Документы
The case of single right rotation occur when Insertion of node takes place
into left sub-tree of left child of any node (lets say node z).
So After the Insert, move toward the root, node by node, updating heights,
because only nodes on the path from insertion point toward the root node
have possibly changed in height.
Let the node that needs rebalancing be node Z.
BF = 1 - (-1) = 2
Y
Right Rotation
Example
8
Insert 8
Insert 7
Insert 6
Right Rotation
7
6
Insert 5
BF = 2
5
4
Right Rotation
6
4
Insert 4
6
5
Y
C
A
Unbalanced Tree
Y
C
C
Right Rotation
B
X
A
A
Example:-
3
BF = 3 -1 = 2
Right Rotation
6
5
4
5
4
8
7
Z
Q
Y
Null
Right Rotation
Null
Y
Q
C
Z
Right Rotation
B
B
A
X
A