开发者

sort a huge array

what is the best way to sort a huge array. say I have 1G RAM, array is 16G. What is the most effici开发者_开发问答ent method to do this? I got enough disk for files.


Split into chunks and sort 512MB at a time into 32 files. Then do a streaming merge sort of the files into one file.


If it's an array of integers, you can get by with a naive radix sort (O(n)) and use almost no RAM at all. First question would be "What kind of data is it?". If its arbitrary data, then an external mergesort is probably your best option.

-tjw

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜