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?
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?
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.