Sort with the limited memory

You are looking for external sorting.
The largest cost in these scenarios is often disk IO. So the trick is to use an algorithm that minimises disk IO.
The usual approach is to read suitably large chunks in to memory, sort those chunks, saving them back to disk, then merge the sorted chunks.

A search for “external sorting” or “sort merge” and your technologies of choice should give some good results.

Leave a Comment