Deletion from an AVL Tree
(Assume that we have used the key to find the node q to be deleted.)
Delete the key from the node q it’s in.
Let p be the parent of q. If q had only one child, make it the new child of p and delete q.
If q had two children, move the key of the left child into q and delete the left child node of q.
Since the deletion may have caused the balance factors to change on the nodes on the path from the root to p, we ascend back along this path from p to the root, fixing the balance factors. At each node, we determine the new balance factor and if the node is unbalanced, perform one of the 4 rotations. If we reach a node whose height ends up the same as it was before the deletion, then the balance factors of its ancestors will also keep their old values, and the deletion operation is complete. If we reach the root and rebalance it, then the deletion operation is also complete.