I\'m looking for the best way to calculate a nodes balance in an AVL-tree. I thought I had it working, but after some heavy inserting/updating I can see that it\'s not worki
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?
R
is the right-hand child of the current node N
.
If balance(N) = +2
, then you need a rotation of some sort. But which rotation to use? Well, it depends on balance(R)
: if balance(R) = +1
then you need a left-rotation on N
; but if balance(R) = -1
then you will need a double-rotation of some sort.