Re: sort algorithm
- From: Juha Nieminen <nospam@xxxxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 17:09:12 GMT
Richard Heathfield wrote:
I used bucket-sort. For this application, I heartily recommend it.
Wouldn't a simple counting sort have been much simpler to implement
(and probably faster)? Something like:
size_t counts[101] = { 0 };
for(size_t i = 0; i < 100000000; ++i)
++counts[array[i]];
size_t arrayInd = 0;
for(int cInd = 0; cInd <= 100; ++cInd)
for(size_t counter = 0; counter < counts[cInd]; ++counter)
array[arrayInd++] = cInd;
The speed of this depends heavily on the actual integral type used in
the array. For example in my computer (3.4GHz Pentium4) sorting an array
of ints like this takes about 400ms, but if it's an array of chars
instead, it takes only 170ms.
.
- Follow-Ups:
- Re: sort algorithm
- From: Dann Corbit
- Re: sort algorithm
- From: Richard Heathfield
- Re: sort algorithm
- References:
- sort algorithm
- From: Limbo
- Re: sort algorithm
- From: Richard Heathfield
- sort algorithm
- Prev by Date: Re: Distance point <=> straight line in space
- Next by Date: Re: sort algorithm
- Previous by thread: Re: sort algorithm
- Next by thread: Re: sort algorithm
- Index(es):
Relevant Pages
|