Given the AVL tree below:
23 / \ 19 35 / \ / \ 8 20 27 40 / 38 / 36
Is it possible to simply make one rotation of 40, to the right? Do it something like this:
23 / \ 19 35 / \ / \ 8 20 27 38 / \ 36 40
It still matches the AVL property, which has - + 1 compared to the left subtree.
In the answer, it performs a double rotation, so the subtree at 35 above will look like this:
23 / \ 19 38 / \ / \ 8 20 35 40 / \ 27 36
I donβt understand when to do double rotation and when to do one rotation, if both of them do not violate the height property.
source share