2

Possible Duplicate:
Code to calculate “median of five” in C#

Suppose I have five numbers in a list, say [3,2,1,4,5].

How do I find the median with 6 comparisons?

Community
  • 1
  • 1
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206

1 Answers1

2

Take an optimal sorting network for N=5 which requires 9 comparisons and then prune the unneeded comparisons for outputs 0, 1, 3 and 4. There's an example of this which uses 6 comparisons in the answer to this question.

Community
  • 1
  • 1
Paul R
  • 208,748
  • 37
  • 389
  • 560