Simultaneous minimum and maximum
ID: simultaneous-minimum-and-maximum
The minimum and maximum of a nonempty array can be found with at most pairwise comparisons. Compare consecutive pairs once, retaining smaller entries as minimum candidates and larger entries as maximum candidates. If an entry is unpaired, put it into both candidate sets. Each candidate set has entries, and finding one extremum on entries uses comparisons. Thus the total is , equal to the stated bound; the singleton case uses zero. Balanced divide-and-conquer algorithms can perform both candidate reductions. Pairing is important: arbitrary equal splitting with only a two-element base case does not attain this comparison count at every size.
New to topics? Read the docs here!