Hi Weng,

Sorry to say, but the REAL answer is "The Best Sorting Algorithm"
depends always on WHAT you're sorting, AND on what it's current
"sortedness" state is.

For instance, say you're program's task is to add a few names or
records into a large set of data, like a college directory. That
directory is itself, already sorted (maybe by an index, but it's the
same thing). In this situation, clearly no algoriithm that completely
re-sorts the entire directory, will be fastest. All you need to do is
code a simple but fast binary or indexed search to find where the new
record should be inserted, and then adjust the indecies (records), that
have been affected. No general purpose sort can touch it.

If the data has very few keys (like an integer), then Radix sort will
surely shine, but the data must be held in memory. Reading each
number's digits from a file on a disk somewhere over a network
(especially), just is NOT fast.

For working with huge files of data, mergesort is the best choice.
Saying you're going to beat it is nice - but it's like trying to
outswim a tuna - not likely in practice.

For general purpose sorting, where the stability of the sort isn't
needed (and by stability I mean the order of the original data is
preserved), Quicksort is best. But to sort less than 1,000 items today,
I typically use Shell sort - just because it's smaller, and simpler,
and the difference with today's computers in speed for sorting 1,000
items, is almost unnoticed.

Both Radix and Quicksort can be fine-tuned until your eyes glaze over,
but that's not what I want. I want to spend my time on the program, or
just on life - not fiddling around to get the last 1% (0.01) out of the
performance. Still, there are times... and I prefer to fine-tune
Quicksort, in that case. Long keys or if the data grows a lot bigger
than expected, it's no problem for Quicksort.

For performance, ALWAYS TEST, ALWAYS TEST, ALWAYS TEST, and lastly,
always test. All the pontificating or mathematically correct abstracts
for performance, NEVER EQUAL A SINGLE TEST.  It's like the jockey's got
together and "decided" what horse would win today's race, because
mathematically..., instead of running the actual race!

The ONE technique which can beat ALL the sorting algorithm, and may
give you the sorted data you need, is the distribution count or "bucket
sort". As I mentioned above, NOTHING can touch it, but it's not always
an option - since nothing is actually sorted.

Cleared this right up, didn't I? <grin>

Adak


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to