Converting a heap to a BST in O(n) time?
I think that I know the answer and the minimum complexity is O(nlogn) . But is there any way that I can make an binary search tree from a heap in O(n) complexity? There is no algorithm for building a BST from a heap in O(n) time. The reason for this is that given n elements, you can build a heap from them in O(n) time. If you have a BST for a set of values, you can sort them in O(n) time by doing an inorder traversal. If you could build a BST from a heap in O(n) time, you could then have an O(n) sorting algorithm by Building the heap in O(n) time, Converting the heap to a BST in O(n) time, and