I had tried to implement the codes to implement the way (brute force) to balance the binary search tree, and I found that there is a case (of the tree) and it seems that it cannot be balanced. The tree is
6
\
10
/
8
/ \
7 9
You can obviously find that the right height of this tree is much greater than its left height, so I rotate left the tree around '6', then the new tree will be
10
/
6
\
8
/ \
7 9
Then it becomes that the left height is much greater than its right height, so in the next step I have to rotate right (back to) the tree around node '10'.
It seems that there must be an infinite loop to rotate this tree around its root node (rotate left, right, left, right...and so on) while balancing this tree. Is there a solution to balancing this tree?