I have a maximum heap represented in an array A , and I have the following question :
Is it possible to build a sorted list , based on the maximum
heap - A - in O(n*log(log(n))) ?
My answer : No we can’t ! we can always run on A and execute MergeSort in O(n*log(n))
or a QuickSort in O(n*log(n)) (worst case O(n^2)) .
I thought also maybe to build the actual heap based on A , this would take O(n) , and then extract from there all the elements in O(n*log(n)) , but I gained nothing here .
At the moment I can’t see any option for O(n*log(log(n))) , any ideas ?
If you have a max-heap in an array form then using something like insertion sort on that array should yield pretty good results. A max heap in array form is nearly sorted (descending) and the best case for insertion for is O(n) when the array is nearly sorted. It’ll still has a O(n^2) worst case but I don’t think you’d ever hit the worst case.