Intuition The one idea behind this whole topic
We want just one item from a pile of numbers — the item that would sit at a chosen rank if we bothered to sort everything — but we refuse to pay the full sorting price. The entire topic is a hunt for a pivot (a splitting value) that is guaranteed not to be near the extremes, because a middle-ish pivot lets us throw away a fixed slice of the pile every step and finish in time proportional to the pile's size.
Before you can read the parent note, you must own every symbol it fires at you. We build them one at a time, each anchored to a picture, each earned before use.
Definition Array and its length
An array A is just an ordered row of boxes, each holding one number. We write A = [ 12 , 3 , 5 , … ] . The number of boxes is its length , written n .
Picture a shelf of numbered boxes. The order they sit in is whatever we were handed — not sorted. That "unsorted" fact is the whole reason the topic exists.
Why the topic needs it: every cost in the parent (like O ( n ) ) is measured against this n . If you don't feel n as "how many boxes," phrases like "throw away half the array" are meaningless.
Definition Rank and the target
k
If we did sort the numbers small-to-large, each would get a position from 1 (smallest) to n (largest). The integer k (1 ≤ k ≤ n ) picks which position we want . The answer is the number that would land at position k .
k as "the ranking I care about"
k = 1 → the smallest. k = n → the largest. k in the middle → the median. We never actually sort; we just want to know who ends up at seat k .
Why the tool and not another? We could sort to read off seat k — but sorting answers all n seats when we asked about one . That over-answering is exactly the waste we want to avoid. This is the Order statistics view: the "k -th order statistic" is a fancy name for "the value at rank k ."
Common mistake Off-by-one: is
k counted from 0 or 1?
Why it trips people: most code arrays start at index 0 . The fix: the parent uses 1-indexed ranks (k = 1 is the minimum). So sorted(A)[k-1] in code, but always speak of k as a 1-based seat number.
Definition Big-O — a growth rate, not a stopwatch
O ( ⋅ ) describes how the work grows as the pile grows , ignoring constant multipliers and small terms. O ( n ) = work grows in step with n (double the pile, double the work). O ( n 2 ) = work grows with the square (double the pile, four times the work). O ( n log n ) sits between them.
Intuition The picture: curves pulling apart
Draw three curves against n . The straight line (O ( n ) ) stays low. The gentle bend (O ( n log n ) ) rises a bit faster. The steep bowl (O ( n 2 ) ) explodes. For big piles the gaps are enormous — that gap is the entire prize the topic chases.
Why the topic needs it: the whole point is "O ( n ) worst-case ." Without a feel for these curves, that claim is empty. See Recurrence relations and the Master Theorem for how such costs are computed.
O ( n ) means fast, O ( n 2 ) means slow — always."
Why it feels right: the curves say so for big n . The fix: Big-O hides constants. An O ( n ) method with a big constant (like Median of Medians) can lose to an O ( n log n ) method on real-world sizes. Big-O ranks growth , not raw speed at a given size.
A pivot p is one chosen value from the pile that we use as a dividing line : everything smaller goes left, everything larger goes right.
To partition around p means to physically rearrange the boxes into three zones — smaller than p , equal to p , larger than p — walking through the array once. After partitioning, p sits at its true sorted index even though the rest is still messy.
Definition The pivot's landing index
i
After partitioning, the pivot p occupies exactly the seat it would have in the fully sorted array. Call that seat number i (a rank, counted from 1 like k ). Concretely, if L boxes are smaller than p , then p lands at == i = L + 1 == : there are L elements to its left, so its rank is the next one up. This i is a fact we read off for free from the single partition sweep.
WHY partition at all? Once we know the pivot's landing index i , we compare it to our target seat k :
i = k → the pivot is the answer, stop.
k < i → the answer sits at a smaller rank, look only left.
k > i → the answer sits at a larger rank, look only right.
We just deleted a whole side of the array with one pass. This is the engine of Quickselect and the sibling algorithm Quicksort . The mechanics of the single sweep are the topic of Partitioning (Lomuto vs Hoare) .
Intuition Why the pivot's
quality is everything
If p lands dead centre (i ≈ n /2 ), each side is ≈ n /2 — we halve the pile each step. If p is the min or max (i = 1 or i = n ), one side is empty and we shed a single box. Same O ( n ) work either way, but one path finishes in O ( n ) total and the other crawls to O ( n 2 ) . Choosing a pivot that can't be terrible is the entire battle the parent fights.
The median of a list is its middle value once sorted . For an odd count like 5, it's the 3rd of 5 — two below, two above.
Definition Group median → median of medians
Chop the pile into groups of 5 . Take each group's median (cheap — 5 items is constant work). Collect those medians into a smaller pile and find that pile's median. This final value M is the median of medians , and it becomes our pivot.
WHY this dance? A single "middle-of-a-group" median could still be extreme for the whole array. But the median of the medians is a middle value of middle values — it is surrounded on both sides by a guaranteed slice of the pile, so it can never be a near-extreme pivot.
10 3 n guarantee comes from (the picture)
Line the 5 n groups up in columns , and inside each column sort the 5 boxes top-to-bottom. Now slide the columns so their middle boxes (the group medians) line up in a row, ordered by value — small-median columns on the left, large-median columns on the right (see the figure).
By definition of M , half the group medians are ≤ M : that's ≈ 2 1 ⋅ 5 n = 10 n columns sitting to the left.
In each of those left columns, the median and the two boxes above it (3 of the 5) are ≤ the column's median ≤ M .
So the shaded rectangle of guaranteed-small boxes is 3 rows tall × 10 n columns wide = 10 3 n boxes, all ≤ M .
By the mirror-image argument, ≥ 10 3 n boxes are ≥ M . Hence the other side can hold at most n − 10 3 n === 10 7 n == boxes — that is exactly where the 10 7 n in the recurrence is born. (Contrast with Randomized algorithms , which get a good pivot only on average , with no such rectangle guarantee.)
Definition Ceiling and floor
⌈ x ⌉ ("ceiling") = round up to the nearest whole number: ⌈ 2.2 ⌉ = 3 . ⌊ x ⌋ ("floor") = round down : ⌊ 2.9 ⌋ = 2 . We need these because a pile of n elements split into 5s may leave a short last group — counts must stay whole.
T ( n ) actually measures
T ( n ) is the worst-case total work (count of comparisons and element-moves, up to a constant) the whole Select algorithm does on any input of size n . "Worst-case" means we take the most unlucky input; "total" means we add up every step, including the recursive calls. It is a function of the size n alone, which is why we can write an equation relating T at one size to T at smaller sizes.
Definition The base case — small piles stop the recursion
Recursion must bottom out or it never ends. When ==n ≤ 5 == (or any fixed small threshold), we do not recurse: we simply sort those few boxes directly and read off seat k − 1 (0-indexed) in constant time. So T ( n ) = O ( 1 ) for n ≤ 5 . Every recursive call shrinks the pile toward this floor, guaranteeing termination.
≤ " and not "= " W ec a n ′ t k n o w t h e ∗ e x a c t ∗ s pl i t , b u tw e ∗ ∗ c an ∗ ∗ p r o mi se i t ′ s n o w or se t han t h ese f r a c t i o n s . W or s t − c a se b o u n d s l i v e in t h e l an g u a g eo f " \le$." See Recurrence relations for how such an inequality is solved.
Intuition The punchline symbol:
5 1 + 10 7 < 1
Add the two shrink-fractions: 5 1 + 10 7 = 10 9 . Because that total is less than 1 , the sub-piles together are strictly smaller than the pile you started with — so the work drains to zero fast enough to sum to O ( n ) . If the fractions summed to 1 (as group size 3 does: 3 1 + 3 2 ), the drain stalls and linearity breaks.
Pivot p and landing index i
3n/10 guarantee -> 7n/10 side
Test yourself — each should feel obvious before you open the parent note.
What does n stand for, and is A sorted? n is the number of elements in the array A ; A is not sorted.
What does the target k mean, and is it 0- or 1-indexed? The rank we want; the answer is the value at seat k if A were sorted, counted from k = 1 (1-indexed).
In one sentence, what does O ( n ) versus O ( n 2 ) tell you? How the work grows with pile size — linearly versus quadratically; it ignores constant factors.
What is a pivot, and what does partitioning produce? A chosen dividing value; partitioning rearranges into smaller / equal / larger zones and fixes the pivot's final sorted index.
What is the pivot's landing index i and how do you get it? The rank the pivot occupies after partitioning; if L elements are smaller than p then i = L + 1 , read straight off the partition sweep.
Why does a min/max pivot cause O ( n 2 ) ? It sheds only one element per step (i = 1 or i = n ), so we do linear work n times.
What is the median of a 5-element group? The 3rd value after sorting the 5 (two below, two above).
What is M , the median of medians, and why is it good? The median of all the group medians; a rectangle of 3 n /10 boxes is guaranteed on each side of it, so it can't be near-extreme.
Where does the 7 n /10 come from? At least 3 n /10 elements are guaranteed on each side of M , so the surviving side holds at most n − 3 n /10 = 7 n /10 .
What does T ( n ) measure, and what is its base case? Worst-case total work of Select on size-n input; for n ≤ 5 we sort directly in constant time, T ( n ) = O ( 1 ) .
What do ⌈ x ⌉ and ⌊ x ⌋ do? Round up and round down to the nearest integer, respectively.
Why is 5 1 + 10 7 < 1 the punchline? Because the two recursive sub-piles together shrink the problem by a constant factor < 1 , which is exactly what forces the total work down to O ( n ) .