-
Binary search trees
Hello everyone
Does anyone know how to make an algorithm that transforms a binary search tree into an AVL tree, and yes transforms it and not make another tree (so it will only be done using rotations) and not with the DSW technique... and in C.
So basically the hardest part is treating all the cases since there is 4 types of rotations.
Thank you so much if you help !!
-
No, there are two types of rotation, left-rotation and right-rotation.
First build a random tree, then test out your code that performs rotations.
Once that works, here's an idea:
At each node... find the height of each subtree... if they differ by no more than 1 then make a recursive call for each subtree... otherwise perform a rotation in the appropriate direction... then repeat the above for the current node.