Content deleted Content added
Cup o' Java (talk | contribs) →top: essentially public knowledge, and it’s in the attached citations anyway |
Increased clarity of assumptions of parallel processor. |
||
(10 intermediate revisions by 9 users not shown) | |||
Line 1:
{{Short description|Linear-time, analog algorithm for sorting a sequence of items}}
{{confusing|date=July 2013}}
[[File:Spaghetti sort.gif|thumb|Schematic diagram of spaghetti sorting. The spaghetti can be sorted by removing them from the bundle on the table in the order they stick out.]]
'''Spaghetti sort''' is a [[linear-time]], [[analog computer|analog]] [[algorithm]] for [[Sorting algorithm|sorting]] a sequence of items, introduced by [[
| last = Dewdney
| first = A. K.
Line 27 ⟶ 28:
| date = July 1, 2006
| page = 96
| isbn = 0-9551170-9-7}}</ref> This algorithm sorts a sequence of items requiring ''O''(''n'') 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''(''1'') time.
==Algorithm==
For simplicity, assume we are sorting a list of [[natural number]]s. 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 the 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'', 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, [[big O notation|''O'']](''1''). This is possible because the hand, the spaghetti rods and the table work as a fully [[parallel computing]] device. 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'').
== References ==
Line 43 ⟶ 44:
==External links==
* [http://www.csd.uwo.ca/faculty/akd/ A. K. Dewdney's homepage]
* [
* [http://iffwww.iff.kfa-juelich.de/~ekoch/talks/qc.pdf Classical/Quantum Computing, IFF-Institute] {{Webarchive|url=https://web.archive.org/web/20110719005807/http://iffwww.iff.kfa-juelich.de/~ekoch/talks/qc.pdf |date=2011-07-19 }}
{{sorting}}
Line 50 ⟶ 51:
{{DEFAULTSORT:Spaghetti Sort}}
[[Category:Sorting algorithms]]
[[Category:Metaphors referring to spaghetti]]
|