QUOTE(skwo @ 30 Sep, 2009 - 10:05 PM)

how do I calculate the new balance of the subtree?
Balance = height(left subtree) - height(right subtree). The height algorithm is extremely simple, so I assume that if you're working with AVL trees you know how to implement it.
QUOTE
Should I also calculate the new balance of the parent of non-balanced subtree?
Yes, you should re-calculate the balance of all the nodes you had to visit while performing the addition. You should visit them in the reverse order, starting with the parent of the inserted node. Because the addition is recursive it is very simple to do this.
For example, the addition can look something like this:
CODE
addNode (root, item)
if root is null
root = item
else
add the item to the correct subtree
if height(t.left) - height(t.right) = 2
perform the correct rotations