Optimal BST alg working perfectly in ~O(n^3) time