Deterministic Selection by Median of Medians
Prove a linear worst-case bound for selection by using a pivot with a guaranteed fraction of smaller and larger elements.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Use group medians to guarantee a split
Partition the keys into groups of five, sort each small group and recursively select the median of their medians. For at least approximately half of the complete groups, the group median is at least the pivot. Each such group contributes three keys at least that large. The symmetric argument applies below. In a three-way partition into smaller, equal and larger keys, each strict side then has at most \(7n/10+O(1)\) keys. If the requested rank lands inside the equal bucket, selection is complete.
Bound the sum of recursive input sizes
Grouping and partitioning take linear work. The pivot computation uses about \(n/5\) elements and the remaining selection problem uses at most \(7n/10+O(1)\). Their total is \(9n/10+O(1)\), leaving a constant fraction of \(n\) to absorb nonrecursive work in a substitution proof. Selecting a pivot this way does more setup than sampling one. It gives a deterministic bound that basic randomized quickselect expresses instead as an expectation. Three-way partitioning provides the invariant that also handles repeated keys.[1][2]