Question:
what is the absolute FASTEST way to sort a bunch of integers?
Antony D
2008-12-03 10:35:43 UTC
I need to be able to sort 1 million integers faster then quicksort. The fastest. I get extra points if it only takes "a[range]" executions.
Three answers:
anonymous
2008-12-07 01:12:31 UTC
There is a faster algorithm than O(n log n) time. The downside is that it requires memory that scales with the range of the integers.

The algorithm is called "bucket sort" on wikipedia, and it actually only takes O(n) executions if you use buckets of size 1. The downside, as I said, is that you would need to have one bucket for every integer in the range you're looking at: if your range is from 1 to 1 million, you need an array 1 million long, which shouldn't be a problem. However, if the integers are between 0 and 2^32 -1 (the range of general integers), you're not going to have enough memory to make an array that big. This answer would still be technically right, but I doubt a program that needs an array 4 GB large would be considered viable.
anonymous
2008-12-03 10:46:30 UTC
mergesort and quicksort as two algorithms which sort in O(n log n) time which on average it doesn't come any faster. There is one point to note though that these algorithms can dissolve into linear time for some data sets
anonymous
2014-11-06 21:13:16 UTC
challenging matter. seek on yahoo and bing. that will may help!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...