The function should takes a list xs and constructs a balanced binary search tree consisting of exactly the same set of elements as xs.
The result should be like this: (if the list is [1,2,3,4,5,6,7,8])
Node (Node (Node (Node Empty 1 Empty) 2 Empty) 4 (Node Empty 4 Empty)) 5 (Node (Node Empty 6 Empty) 7 (Node Empty 8 Empty))
that is to say the tree should look like this:
5
/ \
3 7
/ \ / \
2 4 6 8
/
1
rather than this:
5
/ \
4 6
/ \
3 7
/ \
2 8
/
1
Could anybody tell me how to do this? I find I can do the second tree which is not perfectly balanced, but don't know how to do the first one.
I appreciate any help!! Thank you in advance!