Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a list of $2n$ elements, we have to find the $n$'th largest element. Which is the best algorithm (Time complexity + comparison) for this particular problem?

I know that this could be solved in general by sorting or by finding finding the k-th order statistic. But I am looking for something way simpler than k-th order statistic which solves this particular problem due to the $2n$ and $n$'th restriction.

Hurrah!! Problem is solved!


share|cite|improve this question
"Typical approaches... (are) not something that I am looking for." - then, what? It's not too hard to adapt methods for finding the median... – J. M. Aug 1 '12 at 2:50
There is a list of sorting algorithms on Wikipedia ; I don't know anything about sorting, but I think you should at least take the time to read and study it yourself : – Patrick Da Silva Aug 1 '12 at 2:51
Thanks J.M. Now I know how to solve this one :) – AlgoFreak Aug 1 '12 at 2:57
Remove the largest element, and you're finding the median. There is a "well-known" linear-time algorithm for that. – Robert Israel Aug 1 '12 at 2:58
Also… – user2468 Aug 1 '12 at 3:08

Use the median of medians algorithm to find the median in linear time. This is the best possible since all elements must be examined. It is interesting for a number of reasons: it violates the intuition that sorting is the fastest way to accomplish this, it is an optimal algorithm for the median problem and problems with optimal algorithms are rare, and also it calls into question the zero-one-infinity rule by dividing the list into fifths or smaller parts (thirds yields a log-linear algorithm, like sorting). Recently I mentioned this algorithm as an anecdote about the number $5$ itself.

share|cite|improve this answer

Why not sort? Just comparing the $2n$ elements to anything will take $O(n)$ time, and it's easy to see that all $2n$ elements will have to be compared to something. To sort it takes only $O(n\ln n)$ time, worst-case.

EDIT As Robert Israel pointed out, one can find the median in $O(n)$ time. In fact, the selection algorithm can find the $k^{th}$ smallest element in $O(n)$ time. Learn something new everyday.

share|cite|improve this answer
But finding the median can be done in $O(n)$. – Robert Israel Aug 1 '12 at 2:59
...and of course, there are methods for finding the median that don't need a preliminary sorting. – J. M. Aug 1 '12 at 3:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.