Choosing a Rotation

The balance factor of a node is the height of its left subtree minus the height of its right subtree. An AVL tree repairs an unbalanced node, one with a balance factor of or , with one of four rotations: single right, single left, double left-right, or double right-left. The heavy child is the unbalanced node’s child on its taller side.

Solution
  1. A single right rotation.
  2. A left-right double rotation.
  3. A single left rotation.
  4. A right-left double rotation.
  5. A single left rotation.
Solution

A single left rotation at 10 only moves the bend to the other side. 30 ends on top with a balance factor of , with 10 as its left child and 20 as 10’s right child:

    ╭────╮
    │ 30 │
    ╰──┬─╯
   ┌───┘
╭──┴─╮
│ 10 │
╰──┬─╯
   └───┐
    ╭──┴─╮
    │ 20 │
    ╰────╯