TOPICS
Search

Sorting Network


A sorting network is a fixed arrangement of compare-and-exchange operations that performs sorting on every input. Each comparator reads two values, sends the smaller to one specified output wire, and sends the larger to the other. The pairs of wires compared and the direction of each comparator are fixed before the input values are known (Bose and Nelson 1962, Knuth 1998).

The size of a sorting network is the number of comparators. In a layered network the depth is the number of layers, with comparators in a layer acting on disjoint pairs of wires. For example, the network on three wires that compares (1,2), (2,3), and (1,2) in that order, always sending the smaller value to the lower-numbered wire, has size and depth 3.

By the zero-one principle, a comparator network sorts arbitrary inputs iff it sorts every input whose values are 0 or 1 (Knuth 1998). A threshold that maps each value to 0 or 1 in nondecreasing order commutes with each comparator. If the output contains an inverted pair, a threshold separating its two values produces an unsorted binary output.

Let S(n) be the least number of comparators in a sorting network on n inputs. The Bose-Nelson sorting problem asks for S(n) (Bose and Nelson 1962). Juillé (1995) constructed a 45-comparator network on 13 inputs. Tomar (2026a) reports a computer-assisted lower bound of 45 for this size, so S(13)=45. The lower bound uses an exhaustive search with a certificate. Tomar reports Lean kernel checks for both the lower bound and the 45-comparator construction (Tomar 2026ab). These are results about size.


See also

Sorting

Explore with Wolfram|Alpha

References

Bose, R. C. and Nelson, R. J. "A Sorting Problem." J. ACM 9, 282-296, 1962. https://doi.org/10.1145/321119.321126.Juillé, H. "Evolution of Non-Deterministic Incremental Algorithms as a New Approach for Search in State Spaces." In Proc. Sixth International Conference on Genetic Algorithms (Ed. L. J. Eshelman). San Francisco, CA: Morgan Kaufmann, pp. 351-358, 1995. https://www.demo.cs.brandeis.edu/papers/icga95.pdf.Knuth, D. E. The Art of Computer Programming, Vol. 3: Sorting and Searching, 2nd ed. Reading, MA: Addison-Wesley, 1998.Tomar, T. S. "Sorting Networks on 13 Inputs Need 45 Comparators." Version 6. Zenodo, 2026a. https://doi.org/10.5281/zenodo.24523931.Tomar, T. S. "A Kernel-Checked Lean Proof That Sorting Networks on 13 Inputs Need 45 Comparators." Zenodo, 2026b. https://doi.org/10.5281/zenodo.23603571.

Cite this as:

Weisstein, Eric W. "Sorting Network." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/SortingNetwork.html

Subject classifications