Next: , Previous: , Up: comparisons   [Index]


1.17.11 Minimum and maximum values

Function: min-compare compare x1 ...
Function: max-compare compare x1 ...

A minimum or maximum of the values x1 ... (one or more values) with respect to the compare procedure compare.

The result is the first value that is minimal (maximal, respectively). The order in which the values are compared is unspecified, but each value is compared at least once (even if there is just one value).

Function: kth-largest compare k x0 ...

The k-th largest element of values x0 ... (one or more values) with respect to the compare procedure compare.

More precisely:

(kth-largest compare k x0 ... xn-1)

returns the (modulo k n)-th element of the unique sequence obtained by stably sorting x0, …, xn-1. (Recall that a sorting algorithm is stable if it does not permute items with equal key, i.e. equivalent w.r.t. compare).

The argument k is an exact integer, and n > 1. The order in which the values xi are compared is unspecified, but each value is compared at least once (even if there is just one value).

NOTE The 0–th largest element is the minimum, the (n-1)-th largest element is the maximum. The median is the ((n - 1)/2)-th largest element if n is odd, and the average of the (n/2 - 1)-th and n/2-th largest elements if n is even.