Skip to content

quickselect

quickselect<T>(items, k, compare): T

Defined in: select/quickselect.ts:15

Rearranges items in place until the element at index k is the one a full sort by compare would have put there, and returns it — Hoare’s selection algorithm.

O(n) average, O(n²) worst case.

T

T[]

Working array, modified in place. k must be a valid index.

number

The rank to resolve (0-based).

Comparator<T>

Total order to select by.

T

The value that belongs at index k.