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
  • 19,401
  • 30
  • 112
  • 205

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
  • 202,568
  • 34
  • 375
  • 539