> The Space required to store the elements in Heap is O(n).
I don't think this algorithm is suitable for trillions of items.
The n log n approach definitely works though.