14
Stack Exchange
votes

Is it possible to find the median with a linear size sorting network?

Posted on 12/9/2014
UQ ID:38
Science
Theoretical Computer Science
Original

Is there a sorting network that makes only comparisons and finds the median?

The AKS sorting network sorts with parallel steps, but here I am only interested in the number of comparisons. The median of medians algorithm finds the median with comparisons, but it cannot be implemented as a sorting network.

Remark. In fact, in a recent work, we needed a version that is less powerful than pairwise comparison and resembles sorting networks. In our model one could input two elements, and , and the output was either "a" or "b", such that the output is at least as big as the other number. (In case of equality, either one of them, and we are interested in worst case complexity.) In this variant we could prove that there is a solution with comparisons. Of course I am also interested if anyone knows anything about this model ever being studied.

Keywords & Tags
ds.algorithms
sorting
sorting-network
selection
Model Answers (9)
Submitted answers from various AI models
Unsolved
No reviews yet

K2-Think

Pending UQ Validation
Needs Human Verification
MBZUAI-IFM
Qwen2.5-32B
Sep 18, 2025, 01:50 PM

To determine if a sorting network with ( O(n) ) comparisons can find the median, we first clarify the definition of a sorting network: a fixed sequence of comparators (each comparing and swapping two elements if out of order) that sorts any input array. The goal is to check if such a network can exist with linear comparison count while outputting the median.

Key Observations:

  1. **Sorting N...
0 model reviews
0 human reviews
No reviews yet

GPT-5

UQ Validated
Needs Human Verification
OpenAI
Sep 2, 2025, 06:56 AM

Short answer: This is open.

More detail:

  • Model. A “sorting network” here means a fixed (oblivious) comparator network: the sequence of compare–exchange operations does not depend on the input. One can specialize such a network to compute only the median (or, more generally, the k-th order statistic), often called a selection network.

  • Upper bounds. The best general deterministic constructions...

0 model reviews
0 human reviews
No reviews yet

o4 mini

Failed UQ Validation
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

No “linear‐size” oblivious median‐finding network is known, and nobody has proved one impossible beyond the trivial Ω(n) bound. In fact all of the classic “sorting‐network” constructions (Batcher’s bitonic or odd–even networks, AKS, etc.) use Θ(n log n) comparators, and the obvious way to get the median is to sort and then read off the middle wire. On the lower‐bound side the only general fact i...

0 model reviews
0 human reviews
No reviews yet

o3

Failed UQ Validation
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

Short answer
Nobody knows. The best upper bound that is known for an oblivious comparator (sorting) network which outputs only the median of n keys is Θ(n log n) comparators – we can always sort and take the middle element – and the best lower bound that is known is the obvious Ω(n). No super-linear lower bound and no o(n log n) construction is known. In particular, it is an open problem ...

0 model reviews
0 human reviews
No reviews yet

o3 Pro

UQ Validated
Failed Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

Short answer
Nobody knows. The best lower bound we have for an (oblivious) comparator / sorting-network that outputs the median is Ω(n) comparisons, while the best upper bound that is known is still O(n log n). Whether the two bounds can be closed, i.e. whether Θ(n) comparators are sufficient, has been an open problem for more than thirty years.

-----------------------------------------------...

0 model reviews
0 human reviews
No reviews yet

Gemini 2.5 Pro

Failed UQ Validation
Needs Human Verification
Google
Aug 1, 2025, 12:00 AM

Excellent question that touches on a fundamental and often misunderstood topic in the theory of computation: the distinction between adaptive algorithms and non-adaptive networks.

Short Answer

No, it is not possible to find the median with a sorting network of linear size. The size of any sorting network that correctly finds the median of n elements (a selection network) is Ω(n log n)....

0 model reviews
0 human reviews
No reviews yet

Claude 3.7 Sonnet

Failed UQ Validation
Needs Human Verification
Anthropic
Aug 1, 2025, 12:00 AM

Finding the Median with a Linear-Size Sorting Network

Based on established computational complexity theory, I believe it's not possible to find the median with a sorting network using only O(n) comparisons.

Why This Is Likely Impossible

Sorting networks are non-adaptive by definition - the sequence of comparisons is fixed in advance and cannot change based on the outcomes of previous c...

0 model reviews
0 human reviews
No reviews yet

DeepSeek R1

Failed UQ Validation
Needs Human Verification
DeepSeek
deepseek-ai/DeepSeek-R1
Aug 1, 2025, 12:00 AM
<think> We are asked whether it is possible to find the median of n elements using a sorting network that makes only O(n) comparisons.

First, recall that a sorting network is a fixed sequence of comparisons that is data-independent. The network consists of comparators (which compare two elements and swap them if necessary) arranged in a way that for any input, the network sorts the entire sequen...

0 model reviews
0 human reviews
No reviews yet

Claude Opus 4

Failed UQ Validation
Needs Human Verification
Anthropic
Aug 1, 2025, 12:00 AM

This is an excellent question about the fundamental limits of sorting networks for selection problems.

Answer

No, it is not possible to find the median with a linear-size sorting network. This was proven by Alekseev in 1982.

The Impossibility Result

Alekseev proved that any sorting network that finds the median of n elements must use at least Ω(n log n) comparisons. This is a signif...

0 model reviews
0 human reviews
Submit Your Model's Answer
Your submission will be validated by our LLM validator and then by human experts

You need to be logged in to submit an answer