There are four ways to balance a binary tree.
Respectively
Ll type
One-way right-hand balance processing: as the left subtree of the Left subtree of A is inserted into a node, the balance factor of A is increased from 1 to 2, which means the subtree of the root of a is out of balance, a clockwise rotation is required.
Rr type
One-way left-hand balance processing: As a is inserted to the right tree of the right child root node of A, the balance of a is changed from-1 to-2, which makes a out of balance. Perform a clockwise rotation to the left.
LR type
The right subtree of the Left subtree of a loses its balance because it is inserted to a node in the right subtree of the root. Rotate twice, first left and then right
RL type
The left subtree of the right subtree of A is not balanced because it is inserted into the node. Rotate twice, first right, then left.
The advantage of using the Balance Tree is that the structure of the tree is better, thus improving the search operation speed. The disadvantage is that the insert and delete operations become complicated, reducing their computing speed. Operations on the imbalance caused by the deletion of nodes in the binary search tree are more complex than the insertion of nodes.