How to sort millions of rows of data in a file with less/meagre memory

后端 未结 9 482
不思量自难忘°
不思量自难忘° 2021-02-01 06:44

(From here)

I attended an interview last week and this question was asked:

How do you sort a billion rows of data in a file with only 640KB of memory in

9条回答
  •  有刺的猬
    2021-02-01 07:28

    Knuth has a whole section on external sorting; this was commonplace back when there were no hard drives & not much memory, and tape drives were the norm. Look at the wikipedia page, and/or vol. 3 of Knuth's Art of Computer Programming.

    I agree with Robusto's comment:

    Where do you get the file from if you can't use the drive? It's certainly not going to be held in memory.

    Not enough problem definition.

提交回复
热议问题