Learn
Lesson · Dynamic Programming and Sequential Decisions · When to stop

The Secretary Problem, Exactly

Candidates arrive one at a time in a random order and you can only ever compare them with the ones you have already seen. No values, no distribution, no second chances — and yet the chance of ending with the very best is nowhere near hopeless. The optimal rule rejects the first few whatever they are and then takes the first candidate better than all of them, and the probability it succeeds is a harmonic sum: an exact fraction, checked here by playing the rule out on every ordering there is.

you observe RANKS relative to what you have seen, never values reject the first r-1 whatever they are, then take the first record after them P(r) = ((r-1)/n) x sum of 1/(i-1) for i from r to n, and P(1) = 1/n n = 4: P = 1/4, 11/24, 5/12, 1/4 so reject 1, and win 11 times in 24 checked by playing the rule out on all 24 orderings: 6, 11, 10, 6 wins n = 100: reject 37 and win 0.371043; n/e = 36.7879, a LIMIT and not the answer
The rule, its exact probability, and the limit kept in its place

Core ideas

What this lesson establishes

Three ideas: what you are allowed to observe, why the rule has the shape it has, and why the exact table matters more than the famous constant.

1

The observation is a rank, not a value

When candidate k arrives you learn only whether it is the best of the first k. That is a much weaker signal than a number, and it is what makes the problem interesting: you cannot ask whether this one is good enough, only whether it is the best so far. It also makes the answer independent of whatever distribution the qualities came from, which is the unusual and attractive part.

2

Rejecting a fixed prefix is the shape, and it comes from the same trade

A candidate is worth taking only if it is a record, and a record early on is weak evidence — the best of three is often not the best of twenty. So the rule spends a prefix learning the standard and then takes the first candidate that beats it. Rejecting too few means stopping on a weak record; rejecting too many means the best one goes past unclaimed. P(r) is that trade written out.

3

An exact table, and a limit that is not the answer

P(r) is a rational number for every r, so the whole table can be written in fractions and the best r read off it. The familiar n/e is where that best r sits in the limit as n grows, and the page holds it against how many you reject, which is r − 1 and is usually the whole number it rounds to. At small n it is not even an integer, and this course has not built the asymptotics that make it a limit. So it appears on the page rounded and labelled, beside a table that never needed it.

The material

One rule, one harmonic sum, and every ordering counted

What the rule is, where its probability comes from, and the brute-force count that checks every entry.

Definition · The secretary problem and the look-then-leap rule

n candidates of distinct quality arrive one at a time in a uniformly random order. On each arrival you learn only its rank among those seen so far, and must accept or reject immediately; a rejection is final. You succeed only by accepting the best of all n.

The look-then-leap rule with parameter r rejects candidates 1 through r−1 whatever they are, then accepts the first candidate that is better than all of those — and accepts the last candidate if it reaches it. r = 1 means taking the first arrival.

Theorem · The exact success probability

For r ≥ 2, the rule with parameter r succeeds with probability P(r) = ((r−1)/n) × Σ 1/(i−1) summed over i from r to n. For r = 1 it is 1/n.

The argument: the rule succeeds when the best candidate is in position i ≥ r and the best of the first i−1 lies in the rejected prefix. Those are independent, with probabilities 1/n and (r−1)/(i−1). Summing over i gives the formula, and every term is rational.

The lab computes that sum as a difference of two harmonic numbers, exactly, in whole-number numerators and denominators. So the table it prints is a table of fractions rather than decimals, and the best r is whichever row holds the largest of them — a comparison between rationals, with no rounding anywhere in it.

n = 4, sum over i from r to 4 of 1/(i-1) r = 1 P = 1/4 = 0.250000 r = 2 P = (1/4)(1/1 + 1/2 + 1/3) = (1/4)(11/6) = 11/24 = 0.458333 r = 3 P = (2/4)(1/2 + 1/3) = (1/2)(5/6) = 5/12 = 0.416667 r = 4 P = (3/4)(1/3) = 1/4 = 0.250000 the best r is 2: reject 1 candidate, then take the next record checked by playing the rule out on all 4! = 24 orderings: r = 1 wins 6 of 24 = 1/4 the same r = 2 wins 11 of 24 = 11/24 the same r = 3 wins 10 of 24 = 5/12 the same r = 4 wins 6 of 24 = 1/4 the same n/e = 1.4715 -- a LIMIT, held against the 1 you reject, not the best r

Four candidates and a success rate of 11 in 24, which is a little over 45 per cent, from a rule that throws the first candidate away unseen. That is the surprise the problem is famous for, and at n = 4 you can verify it by hand: there are 24 orderings, the rule is unambiguous on each of them, and counting the wins takes a few minutes.

The count, and why it is a real check

The closed form sums a harmonic series; the brute-force count plays the rule out on every permutation of the ranks and counts how often it ends with the best. The two computations share no line of arithmetic: one is a sum of reciprocals, the other is a loop over orderings comparing integers. The lab runs both for any n up to seven and compares them entry by entry, and shows the table as checked only when every entry agrees.

Example · Seven candidates, 5040 orderings

At n = 7 the best r is 3 — reject two, then take the next record — and it succeeds with probability 29/70, about 0.414286. The counts over all 5040 orderings are 720, 1764, 2088, 2052, 1776, 1320 and 720, and every one of the seven fractions matches the closed form exactly.

Notice r = 3 and r = 4 are close: 2088 wins against 2052, which is 29/70 against 57/140. Rounded to two decimals they are both 0.41, and a page that printed decimals would be unable to say which rule was better. That is what the exact table is for.

The limit, and where it belongs

Push the candidate slider to its highest setting, a hundred, and the table is too long to print in full, so the lab shows every eighth row, the best one and the row either side of it. You reject 37, then take the first record, and that succeeds with probability 0.371043. Meanwhile n/e is 36.7879, printed rounded because 1/e is irrational — and rounded to a whole number it is 37, which is exactly how many you reject.

That looks like the constant giving the answer, so it is worth being exact about what it gave. n/e said to look near 37. It did not say that rejecting 37 beats rejecting 36 or 38; only the table does, and it says so by very little. Those are the rows r = 37, r = 38 and r = 39 — the rule’s parameter is one more than the number it rejects — and the lab prints them at 0.371015, 0.371043 and 0.370801. The winner and r = 37 agree to four decimal places and part in the fifth. Nor is the rounding dependable: walk the slider across all 98 settings it reaches and n/e rounded is the number you reject at 80 of them and one too many at the other 18.

This is the only rounded number anywhere on the course and the page labels it. The reason to keep it is that n/e is what a reader will meet everywhere else, and meeting it here as a limit sitting beside an exact table is the right way round: the table is the answer, the constant is a description of how the answer behaves for large n, and the asymptotic argument that makes it a limit is not one this path has built.

What the model left out

Every ordering is equally likely, which is the assumption doing nearly all of the work: it is what makes a record at position i mean the same thing whatever the underlying qualities were. The objective is also unusually harsh — you succeed only by getting the very best, and ending with the second best scores the same as ending with the worst. Change that to maximising expected rank and the optimal rule changes shape entirely.

And nobody can be recalled, nobody refuses, n is known in advance, and there is no cost to looking. Each of those is a modelling decision. The arithmetic here is exact and exhaustively checked, and it is exact about a situation with all four of them true.

Interactive

Look, then leap

An exact harmonic sum, checked by playing the rule out on every ordering

Look, then leapreject the first r − 1 whatever they are, then take the first one better than all of them
the chance of success at each rthe best rthe same figure, counted over every orderingthe n/e limit

Method

Computing the table, and reading it

Four steps. The third is where the exactness earns its keep, and the fourth is the one people skip.

1

Write down what success requires, in one sentence

The best candidate is at position i, and the best of the first i−1 is inside the rejected prefix. Those two events are independent, which is the only probabilistic content of the whole derivation.

2

Sum over the positions the best candidate could occupy

1/n for its position times (r−1)/(i−1) for the prefix condition, summed over i from r to n. The 1/n comes out of the sum and the rest is a difference of harmonic numbers.

3

Keep the entries as fractions and compare them as fractions

At n = 7 the two best rules score 29/70 and 57/140, which round to the same two decimals. Deciding between them requires the exact values, and this is the ordinary case rather than a contrived one — the table is flat near its maximum by construction.

4

Check against the count whenever the count is affordable

Up to seven candidates, play the rule out on every ordering and count. 7! is 5040 and a page can do it; 8! is 40320 and it cannot, so the honest thing at larger n is to say the table is the closed form alone, which is what the lab does.

Ranks, prefixes and an exact table

Score 0 / 0

Four candidates by hand, and seven by counting

At four candidates the whole problem fits on a page: 24 orderings, four rules, and every entry of the closed form checkable against a count.

n = 4 P(r) = ((r-1)/4) x sum of 1/(i-1) for i from r to 4 r the harmonic sum P(r) exactly as a decimal wins 1 - 1/4 0.250000 6 2 1/1 + 1/2 + 1/3 = 11/6 11/24 0.458333 11 3 1/2 + 1/3 = 5/6 5/12 0.416667 10 4 1/3 1/4 0.250000 6 24 orderings walked, the rule played out on each, the wins counted: 6, 11, 10, 6 out of 24 -- every entry matches the closed form best r = 2: reject 1, then take the first candidate better than it n/e = 1.4715 -- the limit; hold it against the 1 you reject, not the 2 n = 7 r 1 2 3 4 5 6 7 wins 720 1764 2088 2052 1776 1320 720 of 5040 P(r) 1/7 7/20 29/70 57/140 37/105 11/42 1/7 dec. 0.1429 0.3500 0.4143 0.4071 0.3524 0.2619 0.1429 best r = 3 -- reject 2 -- winning 29/70; r = 4 is 57/140, and to two places both are 0.41, so only the fractions decide n/e = 2.5752 (rounded), which is 3 -- and you reject 2. Seven is one of the 18 settings where the rounded limit is one too many

The n = 7 row of decimals is the argument for exact arithmetic in one line. The best two rules differ by 36 orderings out of 5040, which is 1/140, and every rounding anyone would reach for erases it. The table is flat near its maximum because that is the shape of the trade, so this is the normal situation rather than an awkward instance.

For a rehearsal, work out the n = 3 table by hand: six orderings, three rules, and the answer is that r = 2 wins three times in six while r = 1 and r = 3 each win two. Then check it against the closed form. It is the smallest case with a genuine decision in it, and doing it by hand is the fastest way to understand what the rule actually does on a permutation.

The harder rehearsal: move the slider from three candidates upwards one at a time and write down, at each setting, how many the lab says to reject beside n/e rounded. The two agree at 80 of the 98 settings the slider reaches and part at 18 of them — 7, 10, 15, 18, 26, 29, 34, 37, 45, 48, 56, 64, 67, 75, 83, 86, 94 and 97 — and at every one of those the rounded constant is one too many. Finding the first four of them by hand takes a few minutes and settles what the constant is worth better than any sentence here can.

Common mistakes

1
Thinking the rule needs to know the distribution of qualityIt never touches a value. All it uses is the relative rank of each arrival, which is why the success probability is the same whatever the qualities are drawn from — provided every ordering is equally likely. That last condition is the one doing the work, and it is the one to check against a real situation, where arrivals are often anything but exchangeable.
2
Reading n/e as the ruleIt is a limit, and the exact table is the answer. Hold it against the number you reject: at seven candidates it is 2.5752, which rounds to 3, and you reject 2. At a hundred it is 36.7879 and you reject 37, which looks like the constant answering the question — but it is the table that says 37 beats 36 and 38, by a margin that first appears in the fifth decimal place. Quoting the constant as though it were the recipe also quietly imports an asymptotic argument that has not been made anywhere on this path.
3
Forgetting how harsh the objective isSuccess means ending with the very best candidate. Ending with the second best counts exactly the same as ending with the worst or with nobody at all, which is almost never what anyone actually wants. Under a gentler objective — minimising the expected rank of whoever you hire — the optimal rule is a different shape, and the famous answer does not transfer.

Check your understanding

✓
Finish when you can derive P(r) from the two independent events, build the table for four candidates in fractions, and say exactly what n/e is and is not.

You should be able to state what is observed on each arrival, explain why the optimal rule rejects a prefix and then takes a record, derive the success probability as a sum over the best candidate's position, read the best r off an exact table rather than off a limit, and check a small case by playing the rule out on every ordering.

Note: Every recursion so far has bottomed out somewhere: a last stage, a last activity, a last period, a last candidate. The closing lesson removes that. When the process never ends there is no final column to start from, and the value satisfies an equation instead of a recursion — which turns out to be a linear system with an exact solution, while the obvious method of repeated substitution is still climbing towards it. Watching the two side by side is the point, and the denominators tell the story better than the decimals do.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.