Skip to content

5. Selection and Order Statistics

Selection and order-statistics: quickselect, median-of-medians, streaming top-k, heavy hitters, reservoir sampling, and quantile summaries.

indexslugname
116quickselectQuickselect
117randomized-quickselectRandomized Quickselect
118deterministic-selectDeterministic Select
119median-of-mediansMedian of Medians
120introselectIntroselect
121heap-selectHeap Select
122partial-sort-selectionPartial Sort Selection
123nth-elementNth Element
124top-k-by-heapTop K by Heap
125top-k-by-quickselectTop K by Quickselect
126bottom-k-selectionBottom K Selection
127streaming-top-kStreaming Top K
128streaming-heavy-hittersStreaming Heavy Hitters
129misra-griesMisra Gries
130space-saving-algorithmSpace Saving Algorithm
131count-min-sketch-queryCount Min Sketch Query
132median-maintenance-two-heapsMedian Maintenance by Two Heaps
133order-statistic-tree-selectOrder Statistic Tree Select
134order-statistic-tree-rankOrder Statistic Tree Rank
135weighted-medianWeighted Median
136lower-median-selectionLower Median Selection
137upper-median-selectionUpper Median Selection
138multi-selectionMulti Selection
139selection-in-sorted-matrixSelection in Sorted Matrix
140kth-smallest-in-two-sorted-arraysKth Smallest in Two Sorted Arrays
141kth-smallest-pair-distanceKth Smallest Pair Distance
142kth-smallest-subarray-sumKth Smallest Subarray Sum
143kth-smallest-fractionKth Smallest Fraction
144kth-largest-streamKth Largest in Stream
145reservoir-samplingReservoir Sampling
146weighted-reservoir-samplingWeighted Reservoir Sampling
147floyd-samplingFloyd Sampling
148sample-sort-selectionSample Sort Selection
149quantile-summaryQuantile Summary
150greenwald-khanna-quantileGreenwald Khanna Quantile
Randomized QuickselectQuickselect with random pivot selection to achieve robust expected linear time.
2 min
Deterministic SelectSelection algorithm with guaranteed linear time using structured pivot choice.
3 min
Median of MediansChoose a pivot with guaranteed quality by taking the median of group medians.
3 min
IntroselectHybrid selection algorithm that combines Quickselect with worst-case fallback.
3 min
Heap SelectSelect the k-th smallest or largest element by maintaining a heap of candidate values.
3 min
Partial Sort SelectionSelect the k-th element by partially sorting only the needed prefix of the array.
2 min
Nth ElementRearrange an array so that the element at position k is the same as in sorted order, with partition guarantees.
3 min
Top K by HeapFind the k largest or k smallest elements by maintaining a bounded heap.
3 min
Top K by QuickselectFind the k largest elements using partition-based selection in linear time.
3 min
Bottom K SelectionSelect the k smallest elements using bounded structures or partitioning.
2 min
Streaming Top KMaintain the k largest elements while values arrive one at a time.
3 min
Streaming Heavy HittersFind frequent items in a stream using bounded memory.
3 min
Misra GriesFind frequent items in a stream by maintaining a bounded set of counters.
3 min
Space SavingApproximate frequent items in a stream with tighter error bounds than Misra Gries.
3 min
Count Min Sketch QueryEstimate item frequencies in a stream using a compact hash based summary.
4 min
Median MaintenanceMaintain the median of a stream using a max heap and a min heap.
3 min
Order Statistic Tree SelectSelect the element with a given rank from a balanced search tree augmented with subtree sizes.
3 min
Order Statistic Tree RankCompute the sorted-order rank of a key in a search tree augmented with subtree sizes.
3 min
Weighted MedianSelect an element whose total weight on each side is at most half of the total weight.
3 min
Lower MedianSelect the lower median, the element at index floor((n-1)/2), using selection or partitioning.
2 min
Upper MedianSelect the upper median, the element at index floor(n/2), using selection or partitioning.
2 min
Multi SelectionSelect multiple order statistics in one pass more efficiently than repeated selection.
4 min
Sorted Matrix SelectionSelect the k-th smallest element from a matrix whose rows and columns are sorted.
3 min
Kth Smallest in Two Sorted ArraysSelect the k-th smallest element from two sorted arrays without merging them.
4 min
Kth Smallest Pair DistanceFind the k-th smallest absolute difference among all pairs in an array.
3 min
Kth Smallest Subarray SumFind the k-th smallest sum among all contiguous subarrays, usually for nonnegative arrays.
3 min
Kth Smallest FractionSelect the k-th smallest fraction formed by pairs from a sorted array using heap or binary search.
3 min
Kth Largest in StreamMaintain the k-th largest value while values arrive one at a time.
3 min
Reservoir SamplingSelect a uniform random sample from a stream of unknown length using fixed memory.
3 min
Weighted Reservoir SamplingSelect a random sample from a stream where each item has a nonnegative weight.
4 min
Floyd SamplingSelect k distinct integers uniformly from a fixed range without shuffling the whole range.
3 min
Sample Sort SelectionUse sampling to approximate order statistics and refine selection efficiently.
3 min
Quantile SummaryMaintain approximate quantiles of a stream using compact summaries.
3 min
Greenwald Khanna QuantileMaintain deterministic approximate quantiles of a stream with rank error guarantees.
5 min
QuickselectSelect the k-th smallest element in an unsorted array using partitioning.
3 min