I'm studying AVL Trees in my programming class and we got this exercise dealing with right, left, left-right and right-left rotations as a way to check if we understand the theoretical concept of AVL Trees. We're given the numbers $100,50,25,10,37,32,200$. Creating an AVL Tree until $37$ wasn't that difficult but then I got stuck at balancing out the tree when I insert $32$. The following is my method:

enter image description here

Now I know that there is a conflict at $52$ but since it has 3 nodes (LRL), I don't understand how I should rotate. I think, I should get $37$ as the root node $25$ as it's left child and $52$ as it's right child but I dunno.


I think, I should get 37 as the root node 25 as it's left child and 52 as it's right child but I dunno.

You plan is correct.

What you need to do is a left-right rotation as shown in the third column of the table below. That is, a left rotation at node 25 followed by a right rotation at 52. It is symmetric to the right-left rotation as shown in the fourth column and as explained in Wikipedia.

tree rebalancing picture at wikimedia


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.