The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....


Unit: SDL_math1
Class: none
Declaration: function QuickSelect (var Data: array of double; k, First, Last: integer): double;

The function QuickSelect returns the value of the kth smallest element of the unsorted array Data and can be used to calculate a particular quantile of a set of values. The parameter k specifies the rank number of the order statistic, the parameters First and Last specify the indices of the first and the last element of the data array to be included in the calculation (valid range is from 0 to length(Data)-1).

Example: In order to calculate the 95-percentile of the first 100 values in the data array one has to execute the following statement:
perc95 := QuickSelect (data, round(0.95*(Last-First+1)), 0, 99);


The function QuickSelect is much faster than the calculation of quantiles by means of a full sort of the data array. The only drawback is that QuickSelect can calculate only one particular quantile at a time. See the Delphi Bits blog for additional information.

Last Update: 2016-Aug-15