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
精彩评论