rotations both cases and are trivial to implement as they simply adjust balances case is by far the hardest of the cases to implement rotating subtree is the operation that keeps the tree balanced as new nodes are inserted into it for case the tree is in state where new node is going to be added to the tree causing an imbalance that must be dealt with there are two possibilities figure depicts the first of these possible situations the new node may be inserted to the left of the bad childawhen the subtree anchored at the pivot node is already weighted to the left the pivot nodebis the nearest ancestor with non-zero balance for node to have balance - before inserting the new node its right subtree must have height while its left subtree has height adding the new node into the subtree of the bad child would result in the pivot having balance - which is not allowed the right rotation resolves the problem and maintains the binary search tree property the subtree moves in the rotation but before the rotation all values in must have been less then and greater than after the rotation this would also be true which means it remains binary search tree inserting value to the right of the bad child when the imbalance is to the right results in an analogous situation requiring left rotation notice that in either rotation the balance of nodes and are zero this only applies to case and does not hold in the case of double rotation (fig againthe balance of both nodesthe pivot and the bad childbecome zero after the rotation in either direction case is not possible under any other circumstances for case we must deal not only with pivot and bad childbut also bad grandchild as described in the previous sectionthis case occurs when inserting fig avl tree case right rotation this copy belongs to 'acha