Re: problem on medians
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Thu, 31 May 2007 08:39:08 +0000
ak said:
what are the least no. of comparisons to find the medain of a set of
n integers ?
I presume you mean "median".
The answer is of course 0, which occurs when n is 0, 1, or 2. For n = 0,
there is nothing to compare, so no comparisons can occur. When n is 1,
there is only one value, which is its own median, so no comparison is
required. When n is 2, the median is given by the sum of the two
elements divided by 2, and again no comparison is required.
It is also possible, albeit a little harder, to find the median in zero
comparisons when n > 2 provided only that the values are all members of
some simple arithmetic series, in any order but without any gaps and
with the highest and lowest members known.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- Follow-Ups:
- Re: problem on medians
- From: CBFalconer
- Re: problem on medians
- From: d . hutchinson4
- Re: problem on medians
- References:
- problem on medians
- From: ak
- problem on medians
- Prev by Date: Re: Algorithm to extract lines of a tab with the max value for a given reference number
- Next by Date: Re: problem on medians
- Previous by thread: problem on medians
- Next by thread: Re: problem on medians
- Index(es):
Relevant Pages
|