Spaghetti sort
Spaghetti sort is a linear-time, analog algorithm for sorting a sequence of items, introduced by A. K. Dewdney in his Scientific American column. This algorithm sorts a sequence of items requiring O stack space in a stable manner. It requires a parallel processor, which is assumed to be able to find the maximum of a sequence of items in O time.
Algorithm
For simplicity, assume we are sorting a list of natural numbers. The sorting method is illustrated using uncooked rods of spaghetti:- For each number x in the list, obtain a rod of length x.
- Once you have all your spaghetti rods, take them loosely in your fist and lower them to the table, so that they all stand upright, resting on the table surface. Now, for each rod, lower your other hand from above until it meets with a rod—this one is clearly the longest. Remove this rod and insert it into the front of the output list. Repeat until all rods have been removed.