0
$\begingroup$

Prove that there isn't any comparison sort algorithm which for an input of size $n$ can sort at least half of the permutations of the input in linear time. (For the other half the algorithm can return anything, even a completely unsorted array.)

I know that using comparison model of sorting algorithms there is a lower bound of $\Omega(n \log n)$ so I try to make a proof by contradiction and to get to the fact that if such an algorithm exist then we can sort by comparison sort in linear time.

Yuval Filmus
281k27 gold badges317 silver badges514 bronze badges
asked Jul 8, 2016 at 7:46
$\endgroup$
0

2 Answers 2

1
$\begingroup$

Suppose that a comparison-based sorting algorithm sorts the set of permutations $\Pi$ correctly. Construct the comparison decision tree underlying the algorithm, with permutations as leaves. Each permutation in $\Pi$ must appear as a leaf (why?), hence the tree must have depth at least $\log_2 |\Pi|$ (why?).

answered Jul 8, 2016 at 10:21
$\endgroup$
0
$\begingroup$

There are n! possible permutations of n items, which is why we need $\log_2(n)$ comparisons, rounded up to the next integer since we can't have half a comparison, to distinguish them. That number is quite close to $n \cdot \log_2(n / e)$. To sort half of the possible inputs, we need ONE fewer comparison. To get to linear time, we have to restrict the number of inputs a lot more.

On the other hand, we can sort an array for example in 100n comparisons when $\log_2(n / e) < 100$ or $n/e < 2^{100}$ or $n < e \cdot 2^{100}$. The largest computer that I can't afford to buy would sort any array that I could store in memory in 40n comparisons.

answered Dec 7, 2021 at 15:59
$\endgroup$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.