0% found this document useful (0 votes)
4 views

Odd–even sort - Wikipedia

Odd-even sort is a simple comparison sorting algorithm designed for parallel processors, functioning by comparing and swapping adjacent elements based on their odd/even indices until the list is sorted. It operates through alternating passes of odd-even and even-odd comparisons, making it similar to bubble sort but more efficient in parallel processing contexts. The algorithm's correctness is proven through a series of inductive steps that ensure each element is moved to its correct position within a bounded number of passes.

Uploaded by

qzzh0314
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Odd–even sort - Wikipedia

Odd-even sort is a simple comparison sorting algorithm designed for parallel processors, functioning by comparing and swapping adjacent elements based on their odd/even indices until the list is sorted. It operates through alternating passes of odd-even and even-odd comparisons, making it similar to bubble sort but more efficient in parallel processing contexts. The algorithm's correctness is proven through a series of inductive steps that ensure each element is moved to its correct position within a bounded number of passes.

Uploaded by

qzzh0314
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Odd–even sort

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

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. This algorithm was originally presented, and shown to be
efficient on such processors, by Habermann in 1972.[2] Example of odd–even transposition sort
sorting a list of random numbers.
The algorithm extends efficiently to the case of multiple items per processor. In the Baudet–Stevenson
Class Sorting
odd–even merge-splitting algorithm, each processor sorts its own sublist at each step, using any
algorithm
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.[3] Data structure Array
Worst-case performance

Batcher's odd–even mergesort Best-case performance


Worst-case space
A related but more efficient sort algorithm is the Batcher odd–even mergesort, using compare–
complexity
exchange operations and perfect-shuffle operations.[4] Batcher's method is efficient on parallel
processors with long-range connections.[5] Optimal No

Algorithm
The single-processor algorithm, like bubblesort, is simple but not very efficient. 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.length - 1; i += 2) {
if (list[i] > list[i + 1]) {
swap(list, i, i + 1);
sorted = false;
}
}
for (var i = 0; i < list.length - 1; i += 2) {
if (list[i] > list[i + 1]) {
swap(list, i, i + 1);
sorted = false;
}
}
}
}

Proof of correctness
Claim: Let be a sequence of data ordered by <. The odd–even sort algorithm correctly sorts this data in passes. (A pass here is
defined to be a full sequence of odd–even, or even–odd comparisons. 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.[6]

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,[7][8] it suffices to check correctness when each is either 0 or 1. Assume that there are
1s.

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. But after the first odd–
even pass, the rightmost 1 will be in an even position. It follows that it will be moved to the right by all remaining passes. Since the rightmost one
starts in position greater than or equal to , it must be moved at most steps. It follows that it takes at most passes to move the
rightmost 1 to its correct position.
Now, consider the second rightmost 1. After two passes, the 1 to its right will have moved right by at least one step. It follows that, for all
remaining passes, we can view the second rightmost 1 as the rightmost 1. The second rightmost 1 starts in position at least and must be
moved to position at most , so it must be moved at most steps. 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. Hence, for all passes after the first two, the second rightmost 1 will
move to the right. It thus takes at most passes to move the second rightmost 1 to its correct position.

Continuing in this manner, by induction it can be shown that the -th rightmost 1 is moved to its correct position in at most passes.
Since , it follows that the -th rightmost 1 is moved to its correct position in at most passes. The list is thus correctly sorted in
passes. QED.

We remark that each pass takes steps, so this algorithm has complexity.

References
1. Phillips, Malcolm. "Array Sorting" (https://web.archive.org/web/20111028201105/http://homepages.ihug.co.nz/~aurora76/Malc/Sorting_Array.h
tm#Exchanging_Sort_Techniques). Homepages.ihug.co.nz. Archived from the original (http://homepages.ihug.co.nz/~aurora76/Malc/Sorting_
Array.htm#Exchanging_Sort_Techniques) on 28 October 2011. Retrieved 3 August 2011.
2. N. Habermann (1972) "Parallel Neighbor Sort (or the Glory of the Induction Principle)," CMU Computer Science Report (available as
Technical report AD-759 248, National Technical Information Service, US Department of Commerce, 5285 Port Royal Rd Springfield VA
22151).
3. Lakshmivarahan, S.; Dhall, S. K. & Miller, L. L. (1984), Alt, Franz L. & Yovits, Marshall C. (eds.), "Parallel Sorting Algorithms" (https://books.go
ogle.com/books?id=Mo2Q-TEwKGUC&pg=PA322), Advances in Computers, 23, Academic Press: 295–351, doi:10.1016/S0065-
2458(08)60467-2 (https://doi.org/10.1016%2FS0065-2458%2808%2960467-2), ISBN 978-0-12-012123-6
4. Sedgewick, Robert (2003). Algorithms in Java, Parts 1-4 (https://books.google.com/books?id=hyvdUQUmf2UC&pg=PA455) (3rd ed.).
Addison-Wesley Professional. pp. 454–464. ISBN 978-0-201-36120-9.
5. Kent, Allen; Williams, James G. (1993). Encyclopedia of Computer Science and Technology: Supplement 14 (https://books.google.com/book
s?id=F9Y4oZ9qZnYC&pg=PA33). CRC Press. pp. 33–38. ISBN 978-0-8247-2282-1.
6. "Five Lectures on CA" (http://liinwww.ira.uka.de/~thw/vl-hiroshima/slides-4.pdf) (PDF). Liinwww.ira.uka.de. Retrieved 2017-07-30.
7. Lang, Hans Werner. "The 0-1-principle" (https://www.inf.hs-flensburg.de/lang/algorithmen/sortieren/networks/nulleinsen.htm). inf.hs-
flensburg.de. Retrieved 30 July 2017.
8. "Distributed Sorting" (http://www.net.t-labs.tu-berlin.de/~stefan/netalg13-9-sort.pdf) (PDF). Net.t-labs.tu-berlin.de. Retrieved 2017-07-30.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Odd–even_sort&oldid=1191110018"

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy