1

I know there are some like:

And there are some impractical ones like:

Some of the above use comparisons and others do not.

Do you know which other Efficient Algorithms or Techniques for sorting numbers exist? You can suggest me one even if it is not applicable in real life or it is impractical but it must be efficient, but it would be better if it is a computational solution.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
Enrique
  • 9,920
  • 7
  • 47
  • 59

5 Answers5

8

Spaghetti sort: You cut lengths of spaghetti to lengths corresponding to numbers you want to sort. Then you tap the bundle of spaghetti down on the table so that all their ends align. Then you pick out the longest ones in order. The setup time is long, but the actual sorting time is constant.

Wikipedia has a whole category of sorting algorithms.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
  • Oh this one sounds interesting =) – Enrique Dec 12 '09 at 18:15
  • 1
    LOL. Speaking as a physicist here, if your working set gets to large (a function of the frictional properties of your spaghetti) this may become unreliable: at some point the tap down procedure may fail due to the force needed to hold the bundle together. I suggest using PTFE speghetti. – dmckee --- ex-moderator kitten Dec 12 '09 at 18:18
  • 1
    "The setup time is long, but the actual sorting time is constant." And you get a tasty and nutritious meal out of it when you've finished. – itowlson Dec 12 '09 at 18:20
  • 1
    @GMan, the sorting time is constant - one tap, bam, and you're done. Reading the results is linear. – Paul Tomblin Dec 12 '09 at 18:21
  • Actually, the sorting time is proportional to the length of the longest spaghetti. It takes time for the rest of the spaghetti to move that distance, remember. – Anon. Dec 12 '09 at 18:43
  • Pancake sort sounds more delicious. http://en.wikipedia.org/wiki/Pancake_sorting – Ewan Todd Dec 12 '09 at 18:45
  • 1
    @itowlson: not quite - you still have to cook it. At which point, of course, extracting the correct order becomes significantly more difficult. – Tom Anderson Nov 29 '10 at 13:01
  • Does this need physx or what ? :D – huseyin tugrul buyukisik Feb 15 '14 at 11:06
3

Python uses an algorithm called timsort.

Community
  • 1
  • 1
Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
1

There are sorting networks, which can be an efficient way of sorting if you know in advance how many items you have to sort.

Dan Dyer
  • 53,737
  • 19
  • 129
  • 165
1

natural mergesort is different enough from "plain mergesort" to be worth mentioning separately (just like quickersort is enough of a variation on quicksort to be worth mentioning, but even more so). Python's timsort, which Ned's answer mentions, is based on natural mergesort, btw.

Oh, and, there's Dobosiewicz sort AKA "comb sort", which "stands to bubblesort as shellsort stands to insertion sort" (nothing especially efficient, but still worth mentioning).

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
1

A nice variation of Heapsort is Smoothsort. It performs better than Heapsort if the data is already almost sorted (O(n) instead of O(n log n)).

Whoever
  • 33
  • 1
  • 7