Is this the best way to rotate the below AVL tree?

Viewed 29

original avl tree

In an exam paper I had following AVL tree. Need to insert 27 and 69 and check what type of rotation that is needed. My answer:

I inserted 27 on the right of 23 and 69 on the right of 67.

So far the answer should be good. my only problem is how to rotate this . I was thinking to rotate it into the following rotate

Can someone confirm this is the best way to do it since i am still shaky in this topic! Thank you

1 Answers

This is indeed how the AVL tree will be balanced. The insertion of 69 will (should!) trigger a simple left-rotation, as also pictured on Wikipedia, where , , and 4 correspond to respectively 54, 67 and 69 in your tree:

enter image description here

Related