You need to take the root, insert it into both left and right node, and then assign the whole new array to the set of N.

Then, you can perform the binary search (ie log n) on the set of N, which will give you a balanced AVL tree.

The set of X is only used when you're deleting the contents of a map, idiot

Even then, it's not CPU efficient, the Bjuren-Cooper bubblesort inverse insertion algorithm is so much faster.

__________________