Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Pairwise sorting network

From Wikipedia, the free encyclopedia
Pairwise sorting network
Visualization of the Pairwise sorting network with 16 inputs
Visualization of the Pairwise sorting network with 16 inputs
ClassSorting algorithm
Data structureArray
Worst-caseperformance(logn)(logn+1)/2{\displaystyle (\log n)(\log n+1)/2} parallel time
Worst-casespace complexityn(logn)(logn1)/4+n1{\displaystyle n(\log n)(\log n-1)/4+n-1} space and sequential time
OptimalNo

Thepairwise sorting network is asorting network discovered and published by Ian Parberry in 1992 inParallel Processing Letters.[1] The pairwise sorting network has the same size (number of comparators) and depth as theodd–even mergesort network. At the time of publication, the network was one of several known networks with a depth ofO(log2n){\displaystyle O(\log ^{2}n)}. It requiresn(logn)(logn1)/4+n1{\displaystyle n(\log n)(\log n-1)/4+n-1} comparators and has depth(logn)(logn+1)/2{\displaystyle (\log n)(\log n+1)/2}.

The sorting procedure implemented by the network is as follows (guided by thezero-one principle):

  1. Sort consecutive pairwise bits of the input (corresponds to the first layer of the diagram)
  2. Sort all pairs into lexicographic order by recursively sorting all odd bits and even bits separately (corresponds to the next three layers of 2+4+8 columns of the diagram)
  3. Sort the pairs in nondecreasing order using a specialized network (corresponds to the final layers of the diagram)

Relation to Batcher odd-even mergesort

[edit]

The pairwise sorting network is very similar to the Batcher odd-even mergesort, but differs in the structure of operations. While Batcher repeatedly divides, sorts and merges increasingly longer subsequences, the pairwise method does all the subdivision first, then does all the merging at the end in the reverse sequence. In certain applications like encoding cardinality constraints, the pairwise sorting network is superior to the Batcher network.[2]

Pseudocode

[edit]
 n ← length of array k ← smallest power of two, k ≥ nfor k/2 ≥ p ≥ 1, pin k/2, k/4, k/8, … 4, 2, 1do(these comparisons can all be done in parallel)for 0 ≤ a < n, ain 0, p*2, p*4, p*6, p*8, p*10, …dofor 0 ≤ b < p, bin 0, 1, 2, … p-3, p-2, p-1do       i ← a + b       j ← a + b + pif j < nthen compare and swap elements i and jend iffor k/2 ≥ q ≥ p*2, qin k/2, k/4, k/8, … p*8, p*4, p*2do(these comparisons can all be done in parallel)for 0 ≤ c < n, cin 0, p*2, p*4, p*6, p*8, p*10, …dofor 0 ≤ d < p, din 0, 1, 2, … p-3, p-2, p-1do         i ← c + d + p         j ← c + d + qif j < nthen compare and swap elements i and jend ifrepeat qrepeat p

References

[edit]
  1. ^Parberry, Ian (1992),"The Pairwise Sorting Network"(PDF),Parallel Processing Letters,2 (2, 3):205–211,doi:10.1142/S0129626492000337,S2CID 2986739, archived fromthe original(PDF) on 2019-10-29
  2. ^"Sorting Networks".

External links

[edit]


Theory
Exchange sorts
Selection sorts
Insertion sorts
Merge sorts
Distribution sorts
Concurrent sorts
Hybrid sorts
Other
Impractical sorts


Stub icon

Thisalgorithms ordata structures-related article is astub. You can help Wikipedia byadding missing information.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Pairwise_sorting_network&oldid=1313822723"
Categories:
Hidden category:

[8]ページ先頭

©2009-2026 Movatter.jp