As I read in Introduction To Algorithms [3rd edition]:
MaxHeap is used to sort an array into ascending order, while MinHeap is used to sort an array into descending order.
And the tree below can be written in array format as
20 5 10 12 15 8 2 6 2 9
20
5 10
12 15 8 2
6 2 9
My question is, why don't we use it reversely? For example, if we build a MaxHeap from an unordered array, it is already in descending order. It seems redundant to sort again and range it into complete reverse order.
I really appreciate it if anyone can explain this to me.
If the question is why we prefer data in form of a sorted array but in a three. I think that the answer is that the access of an element in the three is O(log(n)) while the access to the element in the array is O(1) and it is faster operation.