General Insertion Algorithm

  1. Do a normal BST insert.

  2. If tree is balanced, stop.

  3. Starting from new node, find first imbalanced ancestor. This node becomes the pivot; its taller subtree is the rotator.

  4. The new value was inserted in one of the rotator's subtrees (the taller one).