ArticleslgStudy

computer science

Pairwise sorting network

Pairwise sorting network is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Pairwise sorting network rather than just read about it. In short: The pairwise sorting network is a sorting network discovered and published by Ian Parberry in 1992 in Parallel Processing Letters. The pairwise sorting network has the same size (number of comparators) and depth as the odd–even mergesort network.

Pairwise sorting network — main illustration
Pairwise sorting network — illustration

Key takeaways

  • Pairwise sorting network belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Pairwise sorting network to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Pairwise sorting network from memory before moving on to harder problems.

Reference excerpt

The pairwise sorting network is a sorting network discovered and published by Ian Parberry in 1992 in Parallel Processing Letters. The pairwise sorting network has the same size (number of comparators) and depth as the odd–even mergesort network. At the time of publication, the network was one of several known networks with a depth of O ( log 2 ⁡ n ) {\displaystyle O(\log ^{2}n)} . It requires n ( log ⁡ n ) ( log ⁡ n − 1 ) / 4 + n − 1 {\displaystyle n(\log n)(\log n-1)/4+n-1} comparators and has depth ( log ⁡ n ) ( log ⁡ n + 1 ) / 2 {\displaystyle (\log n)(\log n+1)/2} . The sorting procedure implemented by the network is as follows (guided by the zero-one principle):

Sort consecutive pairwise bits of the input (corresponds to the first layer of the diagram) 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) Sort the pairs in nondecreasing order using a specialized network (corresponds to the final layers of the diagram)

Relation to Batcher odd-even mergesort 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.

Pseudocode n ← length of array k ← smallest power of two, k ≥ n for k/2 ≥ p ≥ 1, p in k/2, k/4, k/8, … 4, 2, 1 do (these comparisons can all be done in parallel) for 0 ≤ a < n, a in 0, p*2, p*4, p*6, p*8, p*10, … do for 0 ≤ b < p, b in 0, 1, 2, … p-3, p-2, p-1 do i ← a + b j ← a + b + p if j < n then compare and swap elements i and j end if for k/2 ≥ q ≥ p*2, q in k/2, k/4, k/8, … p*8, p*4, p*2 do (these comparisons can all be done in parallel) for 0 ≤ c < n, c in 0, p*2, p*4, p*6, p*8, p*10, … do for 0 ≤ d < p, d in 0, 1, 2, … p-3, p-2, p-1 do i ← c + d + p j ← c + d + q if j < n then compare and swap elements i and j end if repeat q repeat p

References

External links Sorting Networks – Archive of web page by the author.

Illustrations

Pairwise sorting network illustration

Worked examples

Example 1 — a first encounter with Pairwise sorting network

Start with the simplest possible case. Write down what Pairwise sorting network claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Pairwise sorting network before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Pairwise sorting network ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Pairwise sorting network

In research
Pairwise sorting network appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Pairwise sorting network in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Pairwise sorting network is common in secondary-school and first-year university syllabi. It links to neighbouring topics Algorithms and data structures stubs, Sorting algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Pairwise sorting network outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Pairwise sorting network in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pairwise sorting network means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Pairwise sorting network out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pairwise sorting network in simple terms?

The pairwise sorting network is a sorting network discovered and published by Ian Parberry in 1992 in Parallel Processing Letters. The pairwise sorting network has the same size (number of comparators) and depth as the odd–even mergesort network.

Why does Pairwise sorting network matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Pairwise sorting network?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Pairwise sorting network.

Tags

  • Algorithms and data structures stubs
  • Sorting algorithms

Keep exploring