encyclopegia.org

Cycle sort

Cycle sort is an in-place, unstable sorting algorithm, a comparison sort that is theoretically optimal in terms of the total number of writes to the original array. It is based on the idea that the permutation to be sorted can be factored into cycles, which can individually be rotated to give a sorted result. Unlike nearly every other sort, items are never written elsewhere in the array simply to push them out of the way of the action. Each value is either written zero times, if it is already in its correct position, or written one time to its correct position. This matches the minimal number of overwrites required for a completed in-place sort. Minimizing the number of writes is useful when making writes to some huge data set is very expensive, such as with EEPROMs like Flash memory where each write reduces the lifespan of the memory.

Cycle sort is an in-place, unstable sorting algorithm, a comparison sort that is theoretically optimal in terms of the total number of writes to the original array. It is based on the idea that the permutation to be sorted can be factored into cycles, which can individually be rotated to give a sorted result. Unlike nearly every other sort, items are never written elsewhere in the array simply to push them out of the way of the action. Each value is either written zero times, if it is already in its correct position, or written one time to its correct position. This matches the minimal number of overwrites required for a completed in-place sort. Minimizing the number of writes is useful when making writes to some huge data set is very expensive, such as with EEPROMs like Flash memory where each write reduces the lifespan of the memory. def cycle_sort(array) -> int: """Sort an array in place and return the number of writes.""" writes = 0 # Loop through the array to find cycles to rotate. # Note that the last item will already be sorted after the first n-1 cycles. for cycle_start in range(0, len(array) - 1): item = array[cycle_start] # Find where to put the item. pos = cycle_start for i in range(cycle_start + 1, len(array)): if array[i] The next implementation written in C++ simply performs cyclic array sorting. template void cycle_sort(type_array *Array, int array_size) { for (int cycle_start = 0; cycle_start ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Cycle sort." encyclopegia.org, 2026, https://encyclopegia.org/wiki/cycle-sort. Accessed 24 November 2026.

Chicago

"Cycle sort." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/cycle-sort.

APA

encyclopegia.org. (2026). Cycle sort. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/cycle-sort

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

Related articles

carbon cycle

stub · references available

business cycle

stub · references available

carbonate–silicate cycle

stub · references available

Calvin cycle

stub · references available

cycle

stub · references available

Cycle of the months

stub · references available

life cycle assessment database

stub · references available

thorium fuel cycle

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1372636393 · 0.5 · snapshot enwiki-001372636393

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.