A selection algorithm is a computational procedure that, given a finite set of elements equipped with a total order and an integer k, determines the k‑th smallest (or largest) element in the set. This problem is often called the selection problem or the order‑statistics problem. The output is frequently referred to as the k‑th order statistic of the input.
Common categories
| Category | Typical method | Time complexity (worst‑case) | Remarks |
|---|---|---|---|
| Comparison‑based | Quickselect (Hoare’s algorithm) | O(n) average, O(n²) worst | Uses partitioning similar to quicksort; performance depends on pivot choice. |
| Deterministic linear‑time selection (Median‑of‑Medians) | O(n) | Guarantees linear worst‑case time by recursively selecting a good pivot. | |
| Heap‑based selection | O(n log k) for selecting k smallest | Maintains a max‑heap of size k while scanning the input. | |
| Non‑comparison‑based (when elements are integers in a bounded range) | Counting sort‑based selection | O(n + U), where U is the range size | Exploits the ability to count frequencies; not applicable to arbitrary ordered types. |
Complexity bounds
- For comparison‑based algorithms, a lower bound of Ω(n) comparisons is required to select the median (k = ⌈n/2⌉) from an unordered list; this bound also applies to any fixed k. Consequently, linear‑time algorithms are optimal in the comparison model.
- If additional structure is known (e.g., the elements are drawn from a small integer universe), sub‑linear time may be achievable using counting techniques or radix‑based methods.
Typical applications
- Finding the median or other quantiles in statistics and data analysis.
- Implementing “top‑k” queries, such as retrieving the highest‑scoring documents in information retrieval.
- Reducing data size by discarding outliers before further processing.
- Supporting priority‑queue operations where only a subset of extreme elements is needed.
Historical notes
- The earliest selection algorithm dates to C. A. R. Hoare’s 1961 paper introducing Quickselect, a variant of his quicksort partitioning scheme.
- The deterministic linear‑time algorithm (often called the median‑of‑medians algorithm) was independently discovered by Blum, Floyd, Pratt, Rivest, and Tarjan in 1973.
References (representative)
- Hoare, C. A. R. (1961). “Algorithm 65: Find”. Communications of the ACM.
- Blum, M., Floyd, R., Pratt, V., Rivest, R., & Tarjan, R. (1973). “Time bounds for selection”. Journal of Computer and System Sciences.
Note: The information provided reflects established concepts documented in reputable computer‑science references.