Spaghetti sort

Spaghetti sort

Spaghetti sort is a linear-time, analog algorithm for sorting a sequence of items, introduced by Alexander Dewdney in his "Scientific American" column. [Citation
last = Dewdney
first = A. K.
author-link = Alexander Dewdney
title = On the spaghetti computer and other analog gadgets for problem solving
periodical = Scientific American
volume = 250
issue = 6
pages = 19-26
year = 1984
date = June 1984
] [Citation
last = Stauffer
first = Dietrich
authorlink = Dietrich Stauffer
title = Annual Reviews of Computational Physics VI
publisher = World Scientific
date = May 15, 1999
page = 260
isbn = 9810235631
] [Citation
last = Adamatzky
first = Andrew
authorlink = Andrew Adamatzky
title = From Utopian to Genuine Unconventional Computers
publisher = Luniver Press
date = July 1, 2006
page = 96
isbn = 0955117097
] It is used as an example of quantum computing reducing the running time of generalized sorting algorithms from O(Nlog N) to O(N).

Algorithm

For simplicity, assume you're 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". (One practical way of choosing the unit is to let the largest number "m" in your list correspond to one full rod of spaghetti. In this case, the full rod equals "m" spaghetti units. To get a rod of length "x", simply break a rod in two so that one piece is of length "x" units; discard the other piece.)
#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 (initially empty) output list (or equivalently, place it in the last unused slot of the output array). Repeat until all rods have been removed.

Analysis

Preparing the "n" rods of spaghetti takes linear time. Lowering the rods on the table takes constant time (O(1)). This is possible because the hand, the spaghetti rods and the table work as a fully parallel computing device. Then there are then "n" rods to remove so, assuming each contact-and-removal operation takes constant time, the worst-case time complexity of the algorithm is O("n").

The space complexity is also minimal: O("n"), measured in rods of spaghetti.

References

External links

* [http://www.csd.uwo.ca/faculty/akd/ A. K. Dewdney's homepage]
* [http://www.bcri.ucc.ie/~dw5/download/dw20-UC06-sort.pdf Implementations of a model of physical sorting, Boole Centre for Research in Informatics]
* [http://iffwww.iff.kfa-juelich.de/~ekoch/talks/qc.pdf Classical/Quantum Computing, IFF-Institute]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Merge sort — Example of merge sort sorting a list of random dots. Class Sorting algorithm Data structure Array Worst case performance O(n log n) …   Wikipedia

  • Cocktail sort — Class Sorting algorithm Data structure Array Worst case performance О(n²) Best case performance O(n) …   Wikipedia

  • Pigeonhole sort — Class Sorting algorithm Data structure Array Worst case performance O(N + n), where N is the range of key values and n is the input size Worst case space complexity O(N * n) …   Wikipedia

  • Counting sort — In computer science, counting sort is an algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm. It operates by counting the number of objects that have each distinct… …   Wikipedia

  • Comb sort — Class Sorting algorithm Data structure Array Worst case performance O(n log n)[1] …   Wikipedia

  • Cycle sort — Example of cycle sort sorting a list of random numbers. Class Sorting algorithm Data structure Array Worst case performance Θ(n2) …   Wikipedia

  • Odd–even sort — Example of odd even transposition sort sorting a list of random numbers. Class Sorting algorithm Data structure Array Worst case performance …   Wikipedia

  • Flying Spaghetti Monster — Touched by His Noodly Appendage, a parody of The Creation of Adam by Michelangelo, is an iconic image of the Flying Spaghetti …   Wikipedia

  • Sorting algorithm — In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other… …   Wikipedia

  • Bogosort — Class Sorting algorithm Data structure Array Worst case performance [1] Best case performance Ω …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”