Is the tree above an AVL tree Yesno Explain reasons If the t
Is the tree above an AVL tree? (Yes/no) Explain (reasons): If the tree above is an AVL tree, then leave it alone; otherwise, make it an AVL tree. Create a binary search tree, from an empty one, by adding the key values from a, b, c, ... j alphabetical work.
Solution
3. It is not an AVL tree
3a) If we calculate the Balace Factor of the Root of the tree T: height(T.left) - height(T.right)
0-2 = -2
for an AVL tree to be true the absolute value of Balace Factor should be always no more than 1.
I.e. |BalanceFactor(T)| 1
3b) To make it AVL we need to perform rotations in this perticular case the RL rotation on the right branch of the tree
so, the tree becomes
5
4 14
10 17
so, the BF is -1 so it is the AVL tree.
thanks please comment below for any further clarification
