Tree rotation is a seed-tree adjustment operation in a two-fork tree, and each rotation does not affect the result of a mid-order traversal of the two-forked tree.
Tree rotations are typically applied where the local balance of the tree needs to be adjusted.
>> L-and right-handed
The rotation of the tree has two basic operations, namely the left-hand (counterclockwise rotation) and the right-handed (clockwise rotation).
The tree rotation consists of two different ways, namely the left rotation (with p as the hinge) and the right rotation (with Q as the hinge). The two rotations are mirrored, and the inverse of each other.
The initial and final states of the subtree are indicated during the rotation of two kinds of trees.
+---+ +---+ | Q | | P | +---+ +---+ / \ Right rotation / +---+ +---+ -------------> +---+ +---+ | P | | Z | | X | | Q | +---+ ---+ <------------- +---+ +---+ /\ Left rotation / +--- + +---+ +---+ +---+| X | | Y | | Y | | Z |+---+ +---+ +---+ +---+
Where you rotate the detailed steps such as R0, R1, R2 as shown in three steps, the left rotation is as shown in the three steps of L0, L1, L2.
__ / +---+ / +---+ | Q | / | Q | +---+ +---+ +---+ / +---+ +---+ | P | /\ R1 | P |//\ +---+ | Q | R0 +---+/+---+-----> +---+/+---+ R2 | P | +---+----->/\/| Z | / / | Z | -----> +---+/\ +---+ +---+ +---+ +---+ +---+ +---+/+---+ +---+ | X | | Y | | X | | Y | +---+ +---+ | P | | Z | +---+ +---+ +---+ +---+ | X | | Q | +---+ +---+ __ +---+ +---+ / \ / \ / +---+ + ---+ L2 +---+ \ +---+ L0 +---+ +---+| X | | Y | <-----| P | \ | P | <-----| Y | | Z |+---+ +---+ +---+ \ +---+ L1 +---+ +---+ +---+ +---+ / \ \| Q | <-----/\ | Q | +---+ \ +---+ +---+ \ +---+ | X | \ \ | X | \ / +---+ +---+ +---+ +---+ +---+ +---+ | Y | | Z | | Y | | Z | +---+ +---+ +---+ +---+
adjustment of the >>avl tree
The basic operations of the AVL tree generally involve the same algorithms that operate in an unbalanced two-fork search tree. But to do one or more of the so-called "AVL rotations" beforehand or later.
Organized from wikipedia
The rotation of the tree of Learning notes of a binary tree