I've done balancing of the tree(bst>avl) requested by hand and I wonder that it was really easy, so I am not sure whether I've done it correctly.
a / \ b e3 / \ e1 e2
initial state is: 'a' is parent of 'b'(left) and 'e3'(right), 'b' is a parent of 'e1'(left) and 'e2'(right).
applying right rotation gives us:
b / \ e1 a / \ e2 e3
'b' in place of 'a' with child 'e1' on the left and 'a' child on the right, 'a' gets 'e2' of 'b' on the left.
So the questions:
- If e1 is itself a subtree or node containing other elements, can I still do this rotation?
- 2. If e2 and e3 are absent, can I still do this rotation?
example 11; 12;16
16 / 13 / 10
intial state: 16 is a parent of 13 and 13 is a parent of 10. Can I do from it: 13 is a parent of 10(left) and 16(right)
I know it's simplistic, but theory often does not cover these thing assuming it's clear, well not for everyone. Thanks for help,