distinct elements, what is the minimum number of comparisons required to find an element that is neither maximum nor minimum?
Given an unordered list of
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Assume n ≥ 3 , so such element exists. Sort the first three elements and pick the middle element. This cannot be the minimum (otherwise it would be sorted as first position) nor the maximum (otherwise it's the third position). The number of comparisons is simply 3 = O ( 1 ) ; we don't need to look at the rest of the input.