Do you mean topK rather than median, for K small? You certainly cannot build a heap with trillions of items in it.
> 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.