Here's where it gets confusing, the text states "If the balance factor of R is 1, it means the insertion occurred on the (external) right side of that node and a left rotation is needed". But from m understanding the text said (as I quoted) that if the balance factor was within [-1, 1] then there was no need for balancing?
Okay, epiphany time.
Consider what a rotation does. Let's think about a left rotation.
P = parent
O = ourself (the element we're rotating)
RC = right child
LC = left child (of the right child, not of ourself)
P 10
\ \
O 15
\ \
RC 20
/ /
LC 18
?
P 10
\ \
RC 20
/ /
O 15
\ \
LC 18
basically, what happens is;
1. our right child moves into our position
2. we become the left child of our right child
3. our right child's left child becomes our right
Now, the big thing you have to notice here - this left rotation HAS NOT CHANGED THE DEPTH OF THE TREE. We're no more balanced for having done it.
But - and here's the magic in AVL - if we rotated the right child to the right FIRST, what we'd have is this...
P
\
O
\
LC
\
RC
And NOW if we rotate O left, what we get is this...
P
\
LC
/ \
O RC
Magic! we've managed to get rid of a level of the tree - we've made the tree balanced.
Balancing the tree means getting rid of excess depth, and packing the upper levels more completely - which is exactly what we've just done.
That whole stuff about single/double rotations is simply that you have to have your subtree looking like this;
P
\
O
\
LC
\
RC
before you rotate - and you may have to do a right rotate to get into that state. But if you're already in that state, you only need to do the left rotate.