Re: problem on medians



Richard Heathfield wrote:
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.

Harumph. He didn't say "set of n non-negative integers". :-)

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net



--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: problem on medians
    ... I presume you mean "median". ... the median is given by the sum of the two ... with the highest and lowest members known. ... Richard Heathfield ...
    (comp.programming)
  • Re: problem on medians
    ... CBFalconer said: ... I presume you mean "median". ... When n is 1, there is only one value, which is its own median, so ... rjh at the above domain, ...
    (comp.programming)
  • Re: find the bugs
    ... Richard Heathfield wrote: ... 'name' is not a pointer its a 'string'. ... Since he posted it in comp.lang.c, I will continue to presume that he intends it to be C code unless he states otherwise. ...
    (comp.lang.c)
  • Re: Stupid question
    ... I presume it's an old IOCCC winner. ... Richard Heathfield ... rjh at the above domain, ...
    (comp.lang.c)
  • Re: Finding the Median
    ... I presume you mean by the fifth column the one that starts off with 188, ... you appear to be missing the value for this column in the third row. ... I need the Median of Col 5, using a date range of Col 2. ... Sample Data ...
    (microsoft.public.excel.newusers)