Let me try to analyze more comprehensively, For a binary tree that is an avl tree, the height difference of each node from any leaf on the left to any rightmost leaf should be within {-1, 0, 1}.
Insert for AVL:
There are four cases for inserting AVL-L - L L - R R - R R - L
Now, case (a). [if balances> 1] LL (left – left) A node X violates the {-1, 0, 1} constraint and leaves the height greater than the right - gives the first to the left of L has a left child south Y whose left height is greater than the right. again L Action. Rotate around Y clockwise. i.e. one right turn.
case (b) (case LR) Suppose that some Z node must be inserted, for Z it is first evaluated at which the sheet, left or right, is placed. Right if more weight, if less weight. let's say Z ', the new node, wt (Z')> wt (Z), i.e. Z 'is inserted as the right child from Z, case L is R, the whole link ZZ' is rotated counterclockwise, now this is case LL and, therefore, is solved using the above case (a). i.e. one left and one right turn.
(c) [if balance <-1] (case R - R) Similarly, case R - R, just apply the binary search rule for the settings, and this case works. i.e. one left turn.
case (d) (case R - L) It is first converted to the case RR and, therefore, is solved using the above case (c). i.e. one right and then one left.
hi.nitish
source share