encyclopegia.org

Odd–even sort

In computing, an odd–even sort or odd–even transposition sort (also known as brick sort or parity sort) is a relatively simple sorting algorithm, developed originally for use on parallel processors with local interconnections.[src] It is a comparison sort related to bubble sort, with which it shares many characteristics.[src] It functions by comparing all odd/even indexed pairs of adjacent elements in the list and swapping pairs where in the wrong order (where the first is larger than the second).[src] The next step repeats this for even/odd indexed pairs (of adjacent elements).[src] Then it alternates between odd/even and even/odd steps until the list is sorted.[src]

In computing, an odd–even sort or odd–even transposition sort (also known as brick sort or parity sort) is a relatively simple sorting algorithm, developed originally for use on parallel processors with local interconnections.[src] It is a comparison sort related to bubble sort, with which it shares many characteristics.[src] It functions by comparing all odd/even indexed pairs of adjacent elements in the list and swapping pairs where in the wrong order (where the first is larger than the second).[src] The next step repeats this for even/odd indexed pairs (of adjacent elements).[src] Then it alternates between odd/even and even/odd steps until the list is sorted.[src] ==Sorting on processor arrays== On parallel processors, with one value per processor and only local left–right neighbor connections, the processors all concurrently do a compare–exchange operation with their neighbors, alternating between odd–even and even–odd pairings.[src] This algorithm was originally presented, and shown to be efficient on such processors, by Habermann in 1972.[src] The algorithm extends efficiently to the case of multiple items per processor.[src] In the Baudet–Stevenson odd–even merge-splitting algorithm, each processor sorts its own sublist at each step, using any efficient sort algorithm, and then performs a merge splitting, or transposition–merge, operation with its neighbor, with neighbor pairing alternating between odd–even and even–odd on each step.[src] ==Batcher's odd–even mergesort== A related but more efficient sort algorithm is the Batcher odd–even mergesort, using compare–exchange operations and perfect-shuffle operations.[src] Batcher's method is efficient on parallel processors with long-range connections.[src] ==Algorithm== The single-processor algorithm, like bubblesort, is simple but not very efficient.[src] Here a zero-based index is assumed: function oddEvenSort(list) { function swap(list, i, j) { var temp = list[i]; list[i] = list[j]; list[j] = temp; } var sorted = false; while (!sorted) { sorted = true; for (var i = 1; i list[i + 1]) { swap(list, i, i + 1); sorted = false; } } for (var i = 0; i list[i + 1]) { swap(list, i, i + 1); sorted = false; } } } } ==Proof of correctness== Claim: Let a_1, ..., a_n be a sequence of data ordered by n passes.[src] (A pass here is defined to be a full sequence of odd–even, or even–odd comparisons.[src] The passes occur in order pass 1: odd–even, pass 2: even–odd, etc.) Proof: This proof is based loosely on one by Thomas Worsch.[src] Since the sorting algorithm only involves comparison-swap operations and is oblivious (the order of comparison-swap operations does not depend on the data), by Knuth's 0–1 sorting principle, it suffices to check correctness when each a_i is either 0 or 1.[src] Assume that there are e 1s.[src] Observe that the rightmost 1 can be either in an even or odd position, so it might not be moved by the first odd–even pass.[src] But after the first odd–even pass, the rightmost 1 will be in an even position.[src] It follows that it will be moved to the right by all remaining passes.[src] Since the rightmost one starts in position greater than or equal to e , it must be moved at most n - e steps.[src] It follows that it takes at most n - e + 1 passes to move the rightmost 1 to its correct position.[src] Now, consider the second rightmost 1.[src] After two passes, the 1 to its right will have moved right by at least one step.[src] It follows that, for all remaining passes, we can view the second rightmost 1 as the rightmost 1.[src] The second rightmost 1 starts in position at least e - 1 and must be moved to position at most n - 1 , so it must be moved at most (n - 1) - (e - 1) = n - e steps.[src] After at most 2 passes, the rightmost 1 will have already moved, so the entry to the right of the second rightmost 1 will be 0.[src] Hence, for all passes after the first two, the second rightmost 1 will move to the right.[src] It thus takes at most n - e + 2 passes to move the second rightmost 1 to its correct position.[src] Continuing in this manner, by induction it can be shown that the i -th rightmost 1 is moved to its correct position in at most n - e + i passes.[src] Since i \leq e , it follows that the i -th rightmost 1 is moved to its correct position in at most n - e + e = n passes.[src] The list is thus correctly sorted in n passes.[src] QED.[src] We remark that each pass takes O(n) steps, so this algorithm has O(n^2) complexity.[src] ==References==[src]

40 sentences · 40 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Odd–even sort." encyclopegia.org, 2026, https://encyclopegia.org/wiki/odd-even-sort. Accessed 27 November 2026.

Chicago

"Odd–even sort." encyclopegia.org. Accessed November 27, 2026. https://encyclopegia.org/wiki/odd-even-sort.

APA

encyclopegia.org. (2026). Odd–even sort. Retrieved November 27, 2026, from https://encyclopegia.org/wiki/odd-even-sort

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

Related articles

Even

stub · references available

Even Ulving

stub · references available

François Even

stub · references available

Even the Rain

stub · references available

Odd Bang-Hansen

stub · references available

Odd Einar Dørum

stub · references available

Even Money

stub · references available

The Angel of the Odd

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

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
  • Careers — open roles: frontier engineers and sales partners

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