One Repair per Insertion
In the trace on the last page, no insertion needed more than one rotation. An insertion never does. To see why, insert 4 into this tree:
╭────╮
│ 14 │
╰──┬─╯
┌─────┴─────┐
╭──┴─╮ ╭──┴─╮
│ 11 │ │ 17 │
╰──┬─╯ ╰──┬─╯
┌───┘ └───┐
╭─┴─╮ ╭──┴─╮
│ 7 │ │ 19 │
╰───╯ ╰────╯
4 becomes 7’s left child. Follow the path back up from 4. 7 has a balance factor of , which is allowed. 11 has a balance factor of : its left subtree now has height and its right subtree is empty:
╭────╮
│ 14 │
╰──┬─╯
┌──────┴──────┐
╭──┴─╮ ╭──┴─╮
bf = +2 ──▶ │░11░│ │ 17 │
╰──┬─╯ ╰──┬─╯
┌───┘ └───┐
╭─┴─╮ ╭──┴─╮
│ 7 │ │ 19 │
╰─┬─╯ ╰────╯
┌───┘
╭─┴─╮
│ 4 │
╰───╯
11 is left-heavy, and its left child 7 is left-heavy too. That is a straight spine, so a single right rotation at 11 repairs it:
╭────╮
│ 14 │
╰──┬─╯
┌────────┴────────┐
╭─┴─╮ ╭──┴─╮
│░7░│ │ 17 │
╰─┬─╯ ╰──┬─╯
┌────┴────┐ └───┐
╭─┴─╮ ╭──┴─╮ ╭──┴─╮
│ 4 │ │ 11 │ │ 19 │
╰───╯ ╰────╯ ╰────╯
Before the insertion, the subtree at 11 was 11 with the single child 7, so its height was . The insertion made it . The repaired subtree is 7 with two leaves, so its height is again. The left subtree of the root 14 has height , as it did before the insertion. So the balance factor of 14 did not change. No other node above the repair changed either.
An insertion adds one leaf, so it can make a subtree at most one level taller. The first unbalanced node on the way up is the lowest node whose subtree grew too tall on one side. The repair at that node brings its subtree back down by one level, to the height it had before the insertion. Every node above the repair then has the same subtree heights it had before the insertion, so none of them can be out of balance.
So when you insert by hand, follow the path up from the new leaf and stop at the first unbalanced node. Repair it, and you are done.