recategorized by
3,129 views
14 votes
14 votes

Consider the tree given in the below figure, insert $13$ and show the new balance factors that would arise if the tree is not rebalanced. Finally, carry out the required rebalancing of the tree and show the new tree with the balance factors on each mode.

recategorized by

3 Answers

Best answer
16 votes
16 votes

$13$ is less than $14$, so it is placed on the left side of $14$

Now need to be rebalanced. Here $17$ is unbalanced, So, in the $2^{\text{nd}}$ tree we need $1$ right rotation to $17$.

Now, $12$ is unbalanced.To balance it we need $1$ right rotation and $1$ left rotation

edited by
27 votes
27 votes

The insertion of 13 leads to LR imbalance at root. Note LR imbalance can be corrected by :

1. Rotate the  node(which is in 'R' side) anticlockwise.
2. After step 1, we will get LL imbalance, therefore rotate clockwise to balance it.

After this, placed the balanced portion on the remaining tree, and adjust tree(i.e greater value on right side and smaller values on left side).

Refer Below pic for answer:

edited by
16 votes
16 votes

..........

After adding $13$ balancing factor of $17=+2$ and of $12=-1$. Which will lead to $L-R$ problem and it will require $2$ rotations $(1-L\ rotation\ \&\ 1-R\ rotation)$

$1)$ $L-Rotation$

Balancing factor of $17=+2$ and of $15=+2$. Which will lead to $L-L$ problem and it will require $1-R$ rotation.

$2)$ $R-Rotation$

Related questions

6 votes
6 votes
2 answers
1
go_editor asked Dec 19, 2016
2,094 views
Mark the balance factor of each node on the tree given in the below figure and state whether it is height-balanced.
8 votes
8 votes
2 answers
2
go_editor asked Dec 19, 2016
1,614 views
Define the height of a binary tree or subtree and also define a height-balanced (AVL) tree.
8 votes
8 votes
3 answers
3
go_editor asked Dec 20, 2016
3,369 views
Assume that the matrix $A$ given below, has factorization of the form $LU=PA$, where $L$ is lower-triangular with all diagonal elements equal to $1, U$ is upper-triangula...
7 votes
7 votes
3 answers
4
go_editor asked Dec 20, 2016
1,246 views
Are the two digraphs shown in the above figure isomorphic? Justify your answer.