How to merge N files into one in sorted order?

292 views Asked by At

I need to create a one huge sorted file from N small sorted files.

I have already made a research and found that External Sort algorithm is suitable.

But I have a memory constraint (limit of strings into memory < N), so I'm not able to load all first lines of each small file, sort them and after write down into an output file etc.

For instance, this link https://www.algosome.com/articles/how-to-sort-large-file.html isn't suitable because on merge stage he stores all first lines in memory.

Could you help me to figure out the best step by step algorithm or implementation for my case?

Thank you.

0

There are 0 answers