3

what is the best way to sort a huge array. say I have 1G RAM, array is 16G. What is the most efficient method to do this? I got enough disk for files.

3
  • Which programming language are you intending to use? You seem to be most concerned about memory usage. What's the state of the virtual memory; do you even need to care? What's your definition of 'best' - time, minimized swapping, or other? Commented Feb 24, 2011 at 2:37
  • @p.campbell not a practical problem. Focus on algorithm and solution. Thanks :) Commented Feb 24, 2011 at 2:38
  • @p.campbell yeah kinda. I met another big file question before. so came up with this one. still preparing for Amazon interview. LOL~ Commented Feb 24, 2011 at 2:52

2 Answers 2

17

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

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.