encyclopegia.org

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(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.

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(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 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 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, 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). ==External links== A. K. Dewdney's homepage Implementations of a model of physical sorting, Boole Centre for Research in Informatics Classical/Quantum Computing, IFF-Institute

References

No reference rows published for this article.

Cite this article

MLA

"spaghetti sort." encyclopegia.org, 2024, https://encyclopegia.org/wiki/spaghetti-sort. Accessed 25 November 2026.

Chicago

"spaghetti sort." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/spaghetti-sort.

APA

encyclopegia.org. (2024). spaghetti sort. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/spaghetti-sort

Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Flying Spaghetti Monster

stub · references available

Spaghetti Western

stub · references available

"The Spaghetti Incident?"

stub · references available

spaghetti alla puttanesca

stub · references available

Meatballs & Spaghetti

stub · references available

Spaghetti 24 x 7

stub · references available

The Gospel of the Flying Spaghetti Monster

stub · references available

The Spaghetti Family

stub · references available
CC BY-SA 4.0 · tier1-factual · https://en.wikipedia.org/w/index.php?oldid=1248432036 · 0.55 · snapshot spaghetti-sort-851481-d102a5568b846a87 · QID Q7572825

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.