just quick question avl trees. if had tree:
27 / \ 9 50 / \ 2 15 \ 21
why balance answer?:
15 / \ 9 27 / / \ 2 21 50
instead of (or both valid?):
21 / \ 15 27 / \ \ 2 9 50
according retracing algorithm avl tree balancing done in 2 steps:
i. left rotation
done left sub-tree:
| | 9 15 / \ / \ 2 15 => 9 21 \ / 21 2
ii. right rotation
done whole tree:
27 15 / \ / \ 15 50 => 9 27 / \ / / \ 9 21 2 21 50 / 2
the second answer incorrect didn't preserve order of elements.