开发者

sort a huge array

开发者 https://www.devze.com 2023-02-12 20:56 出处:网络
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?

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

精彩评论

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