2

Extracting the median of, say, 51 element, consists of splitting the 51 in a H(ead) group of 25, followed by the median, followed by a T(ail) of 25. All the algorithms that I know end up with the additional property that H and T are such that [min(H), max(H)[ and ]min(T), max(T)] do not overlap.

Is this additional property proven mandatory (I guess yes) ? where can I find the proof (I guess it have been done for long) ?

(This is only for the sake of love for algorithms)

quickbug
  • 4,124
  • 4
  • 14
  • 19

1 Answers1

0

If the elements are not unique, then the two sets can in fact overlap (imagine a list of 51 identical elements....)

If the elements are unique then the non-overlapping property is easy to prove by contradiction. From the partitioning of unique elements we have:

  • x < median for all x in H
  • y > median for all y in H

Suppose H and T do overlap. Then we have:

  • x >= y for some x=max(H), y=min(T)

But that implies:

  • x >= y > median

Which is a contratiction because we aleady know x < median. Hence the two sets cannot overlap.

mikera
  • 101,777
  • 23
  • 241
  • 402
  • You may have not noticed that I used open intervals to account for duplicated values of the median. About your demo, I am not convinced ... imagin a widzard looking at my 51 elements and magically put the median at the 26th position, with no other change in the data. Can you prove that the wizard has secretely partitionned the set? – quickbug Jan 01 '14 at 22:00
  • Ermmm..... I guess I don't understand your question then. If you are saying that the algorithm doesn't necessarily perform a partition, then it is obvious that the head and tail sets *can* overlap. So you're not going to have any luck looking for a proof that they don't..... – mikera Jan 01 '14 at 23:46