Given an array of integers, is there a way to convert it into Binary Search Tree (unbalanced) quickly? I have tried inserting it one by one for each element, but this means that I have to traverse from the beginning for each insertion. It works perfectly, but I think the worst case is O(N^2) for being unbalanced, e.g. the array is sorted. Given a large N, I think it is going to take some time.
Back to my question, is there a way to do this faster than the algorithm that I stated?
For example, given array [4,5,2,3,1], is there a fast way to create this?
4
/ \
2 5
/ \
1 3