Let w be the node that was added that unbalenced the tree
let z be the first node from the w towards the root
where the tree is unbalenced
let y be the child of z with the greater height
let x be the child of y with the greater height,
if there is a tie, choose the ancestor of w
Adding the element to the subtree in y caused the tree
to become unbalenced, and it now has height 2 greater
than the other subtree of z.
What we really want to do now is rotate the tree about x or y,
making x or y the new root of the subtree.
We may need to move some of the subtrees around.
There are 4 possible ways to do this, and all 4 are illustrated
on page 431
y is the right child of x
x is the right child of y (case 1)
x is the left child of y (case 3)
y is the left child of z
x is the left child of y (case 2)
x is the right child of y (case 4)
In case 1 and 2, y is between z and x in an inorder transversal
so make y the root of the new tree.
In each case the non-x child of y will become a child of z
In case 3 and 4, x is between z and y in an inorder traversal
so make x the new root of the subtree
In each case, one child of x will go to y and another will go to z
No matter what, the non-y subtree of z will gain a height of 1
And the y subtree of z will lose one from their heights.