An obvious solution is to first determine the maximum using n-1 comparisons and then, from among the other (n-1) elements, determine the minimum using an additonal n-2 comparisons for a total of 2n-3 comparisons. Thus, 2n-3 comparisons is an upper bound on the complexity of this problem. Is this optimal? Can we do better? Can we demonstrate any non-trivial lower bound?
Assume that there are n distinct values. We will use an adversary argument to show a lower bound.
Initially, there are many conceivable answers to the MaxMin problem, none of which have been ruled out. As each comparison is performed, and the outcome determined, fewer possible answers remain. The adversary gives outcomes to comparisons consistent with all previous outcomes, trying to delay the resolution of the problem.
We need n-1 keys to lose at least one comparison
(the nth key is Max) --
each first Loss is a unit of information.
We need n-1 keys to win at least one comparison
(the nth key is Min) --
each first Win is a unit of information.
Therefore, we need a total of 2n-2 units of information.
The adversary gives outcomes that minimize units of information given. So, when comparing x:y, if x had already lost in a comparison then it is okay to let x lose again.
(A) comparing 2 keys who have never been involved in any comparison will give 2 units of information.
(B) any other comparison can be limited to giving at most 1 unit of information.
After making A comparisons of type A and B comparisons of type B, we will gain at most 2A+B units of information. We need 2n-2 units and the fastest way to get them is to use type A comparisons as much as possible. But it is impossible to use more than n/2 such comparisons, (why??) and so the best we can do is to let A = n/2 and therefore B ≥ n-2, so as to get enough units of information.
The total number of comparisons = A+B ≥ 3n/2 - 2, which is an effective lower bound.
We define the adversary as follows:
Give all keys a weight (a fictitious value used
by the adversary in his diabolical calculations);
initially, for all keys, wt(key) = 1.
When comparing x:y,
if ( wt(x) > wt(y) )
or ( wt(x) = wt(y) > 0 )
then wt(x) := wt(x) + wt(y) )
wt(y) := 0
return outcome x > y
otherwise give answer consistent with previous replies
Notes:
There are n-1 distinct losers and at least ceil(lg n) keys lost to max and so all but one of these must lose again. Therefore, we have a lower bound of n-1 + ceil(lg n)-1 = n + ceil(lg n) - 2 comparisons.
Let X* be the median. To ensure that X* is the median we must have n-1 crucial comparisons enabling the conclusion that, for each other element X, it is known which of X < X* or X > X* holds. That is to say, we must have a DAG of comparisons (where an edge x to y means that we have compared and found that x < y), with a path X to X* for those elements for which we can conclude that X < X* and a path X* to X for those elements for which we can conclude that X < X*. All other comparisons (not used in this crucial DAG) are said to be non-crucial. (Slightly different from discussion in [Baase].)
The adversary partitions the elements into categories Small, Medium, and Large. Initially, all elements are Medium.
When comparing a:b,
If n is odd then there are ≥ (n-1)/2
non-crucial comparisons.
If n is even then there are ≥ (n-2)/2
non-crucial comparisons.
Thus, there are always ≥ floor[ (n-1)/2 ]
non-crucial comparisons which,
when added to the n-1 crucial comparisons gives a lower bound of
n-1 + floor[ (n-1)/2 ].