PuzzleReels
Sections

The Secretary Problem

The maths · Episode 14 · 3:42 · gives the answer

The puzzle

100 candidates are interviewed one at a time in a random order, and after each one he must hire or reject on the spot, knowing only how the people he has met rank against each other. He wins only if he hires the best of all 100.

What is his best strategy, and what are his chances?

The maths, properly

Write N for the number of candidates. The film's rule has one dial, k: let the first k go, whatever they are like, then hire the first one who is better than all of them. If nobody is, he is handed the last in the queue.

Proof one: count the ways to win

This is the film's first route. The bar he carries is the best he has seen, so whoever clears it is the best so far: he only ever hires a best-so-far. So he gets the best of all exactly when the best of all is at some place i after the cut, and nobody between the cut and i was a best-so-far. That second condition says the best of the first i−1 is among the first k.

The best of all is equally likely to be at any of the N places. Given that it is at place i, the best of the i−1 before it is equally likely to be at any of those places, and k of them are in the block he let go. So

P(k)=∑i=k+1N1N·ki−1

which is the claim, written with j=i−1.

Where the top is, exactly. Moving the dial from k to k+1 changes the chance by

P(k+1)−P(k)=Sk+1−1N

Sk+1 shrinks as k grows, so the chances climb while it is more than 1 and fall once it is less: one hump. The best cut-off is the first k at which Sk+1 has dropped to 1 or below. For N=100 that is k=37.

Proof two: where e comes from

This is the film's second route. Measure how far through he is instead of counting: x=k/N, and the best candidate at t=i/N. Each term of the sum is 1N·xt, so the sum is a Riemann sum for

∫x1xtdt=−xlnx

Its derivative is −lnx−1, which is zero at x=1/e, and the height there is −1eln1e=1e. The same number answers how long to wait and how often he wins, because at the peak −lnx=1, so −xlnx equals x. One fact read twice. Over the hundred cut-offs, the film's bars never stray more than 0.0057 from the curve.

The step rule says the same thing in other words. Sk+1 is about ln(N/k), and it drops to 1 when N/k is about e.

Proof three: no other rule does better

The film turns one dial and finds its best setting. It does not show that a cleverer rule, one that reacts to what it sees, could not beat it. None can, and the reason is short.

He sees only how each candidate ranks against the ones before. Two facts about a random order:

  1. The i-th candidate's rank among the first i is equally likely to be any of 1,…,i, whatever happened before.
  2. If the i-th candidate is the best so far, the chance that she is the best of all is i/N, whatever happened before. It is the chance that the best of all is among the first i.

So hiring someone who is not the best so far never wins, and hiring a best-so-far at place i wins with chance i/N. Let V(i) be the best chance he can still have after letting the first i go. By fact 1 it does not depend on what he saw, and V(i)≥V(i+1), because from place i he could always let one more go. At a best-so-far at place i he should hire when i/N≥V(i). The left side only grows with i and the right side only shrinks, so once hiring is right it stays right. The best rule is therefore: let some number go, then take the first best-so-far. That is a cut-off rule, and proof one has found the best cut-off.

Tossing coins does not help either. A rule that picks a rule at random wins with the average of their chances, which is no more than the best of them.

A worked case: the film's ten cards

The film plays ten cards, whose qualities come in the order 9, 1, 7, 6, 2, 10, 4, 5, 8, 3. The best is 10.

k = 0 9 1 7 6 2 10 4 5 8 3 takes the first: not the bestk = 3 9 1 7 6 2 10 4 5 8 3 hires the bestk = 9 9 1 7 6 2 10 4 5 8 3 nobody beats the bar: handed the last
The film's three runs on the same ten cards. Grey: let go. The ring: the one he hires.

With k=0 he hires the first card, a 9. With k=3 the best of the three he lets go is a 9, and the first to beat it is card 6, the 10. With k=9 the 10 is inside the block, nobody after it can beat it, and he is handed the last card, a 3.

On this order every cut-off from 1 to 5 wins. He wins whenever the cut falls between the last two best-so-fars, here the 9 at card 1 and the 10 at card 6, and the hump is that window averaged over every order.

Every setting of the dial on these ten cards
The film's ten cards, 9, 1, 7, 6, 2, 10, 4, 5, 8, 3, at every setting of the dial
kBarCardGotResult
0—19lost
19610the best
29610the best
39610the best
49610the best
59610the best
610103forced last
710103forced last
810103forced last
910103forced last

At ten candidates the best cut-off is 3, which wins 39.9% of the time (0.39869), with k=4 a hair behind at 0.39825. That is 30% of the way through, not 37%: ten is not yet the limit. At 100 the best is 37 with 0.37104, and the top is flat. Every cut-off from 29 to 45 is within one percentage point of the best, and every one from 26 to 49 within two. The film says that anywhere from a quarter to a half of the way through beats one in three; in fact every cut-off from 22 to 54 does.

10 0 28 1 37 2 40 3 40 4 37 5 33 6 27 7 19 8 10 901/e let go k (bars in %)
Every cut-off at 10 candidates
03710001/e 29–45 let go k, of 100
At 100: the bars, −x ln x, and the flat top 29–45

The price

The 37% is not the whole story. He hires nobody exactly when the best of all was in the block he let go, so with the dial at k that happens with probability exactly k/N: here 37/100, or 37.0%. Then he is handed the last in the queue, who is equally likely to be any rank but the first. The rank he ends up with, exactly:

The price at 100 candidates and k = 37: what rank the one he hires has, exactly
He ends up withChance
the best37.10%
the second best13.93%
one of the top five62.78%
one of the top ten66.29%
the bottom half18.69%
nobody, so the last in the queue37.00%

The median hire is the 2nd best, and the mean rank is 20.0. Mostly he does very well, and about one time in five he ends up with someone from the bottom half. Every one of those is the forced last candidate: someone he chose, a best-so-far after 37 others, is in the bottom half with probability below 10−15.

Turn the dial yourself

Pick the number of candidates and the cut-off, and interview. The bars are the exact chance for every cut-off, the gold bar is the best one, and the dashed line is 1/e.

Cut-offs at 100 candidates: the exact chance, and 4,000 seeded runs of each
Let go kExactSimulatedOf the way through
00.01000.01200%
100.23480.226810%
200.32590.320720%
300.36470.360030%
370.37100.379537%
450.36210.363045%
600.30850.303060%
800.17950.186080%
990.01000.011099%

Generalising

Any number of candidates. The step rule finds the best cut-off for any N:

The best cut-off and its chance, for any number of candidates
NN/eBest kChance
31.110.50000
51.820.43333
103.730.39869
207.470.38421
5018.4180.37428
10036.8370.37104
1,000367.93680.36820
10,0003,678.83,6790.36791
1,000,000367,879.4367,8790.36788

For every N up to 10,000 the script finds the best k is N/e rounded either down or up, with k−N/e between −0.74 and 0.32. It is not always the nearest whole number: for 1,841 of those N, rounding N/e to the nearest gives the wrong one, though only by a hair. The best chance falls as N grows, and never reaches 1/e. That is checked for every N up to 10,000, and the next section proves it for every N.

Waiting by the clock

The film's rule needs N: you cannot let 37% of the candidates go without knowing how many there are. Suppose instead that nobody knows how many will come, only that they arrive at independent random times through the day, which runs from time 0 to time 1. Then let everyone who comes before time x go, and hire the first best-so-far after it.

Say N come, and the best of them arrives at time t>x. If nobody came before t, he hires her. Otherwise the best of those who came before t is equally likely to have come at any moment of [0,t], so with chance x/t she came before x, and then nobody between x and t was a best-so-far and he hires the best. So the chance, given t, is (1−t)N−1+(1−(1−t)N−1)x/t, which is x/t+(1−t)N−1(1−x/t). The first part integrates to −xlnx, so

PN(x)=−xlnx+∫x1(1−t)N−1(t−x)tdt

The integral is positive, since t>x all the way along it, so at x=1/e the chance is more than 1/e for every N. He does not need to know N, or even how likely each N is: whatever the number, waiting for 1/e of the day wins more than 1/e of the time. This is Bruss's 1/e-law (1984). One candidate wins 63.2%, which is 1−1/e; two win 43.2%; a hundred win 0.36788, just under the counting rule's 0.37104. Setting the dial by a count that turns out wrong is far worse:

Not knowing how many will come: the dial set to let 37 go, against waiting for 1/e of the day
Candidates who comeLet 37 goWait for 1/e of the day
1010.0%36.8%
303.3%36.8%
5022.5%36.8%
10037.1%36.8%
30026.0%36.8%
1,00012.2%36.8%
10,0002.1%36.8%

This proves the floor. If he does know N, he can draw N random times himself, sort them, and pretend the candidates arrived at those times. That is the clock rule, a rule that tosses coins, and proof three says the best cut-off does at least as well. So the best cut-off wins more than 1/e of the time for every N. The script checks the two against each other for every N up to 60.

What changes if the puzzle changes

He wants a good one, not the best. Best-or-nothing is what makes 37% the answer. If instead he wants the rank of the one he hires to be small on average, the best rule is different: at each place, hire if the expected rank of this candidate is no worse than what he can expect by going on. Hiring the i-th candidate when she ranks r-th among the first i gives an expected rank of r(N+1)/(i+1). Working back from the end gives an expected rank of 3.60 at N=100, against the 37% rule's 20.0. However many candidates there are, it never passes 3.8695, the limit found by Chow, Moser, Robbins and Samuels in 1964.

Hiring to make the expected rank small, rather than to get the best
CandidatesExpected rank, best rule
102.558
1003.603
1,0003.832
1,000,0003.869

He can see scores. The film says he has an ordering and no scores. Suppose each candidate instead comes with a score, drawn independently from a distribution he knows, say uniform between 0 and 1. With a score x in front of him and m still to come, hiring wins if all m score below x, and waiting for the next one above x wins with chance 1/j if j of them do. So he hires a best-so-far when

xm≥∑j=1m(mj)xm−j(1−x)j1j

which is a bar that falls as the queue runs out. With N=100, 60,000 seeded runs of that rule get the best 58.3% of the time. The limit, found by Gilbert and Mosteller in 1966, is 0.5802.

The order is not random. Everything rests on the random order. If whoever sends the candidates in can choose the order, no rule can be sure of more than 1/N. Let them pick a place J at random, send candidates in rising quality up to J, and everyone worse after it. Until J every candidate is a best-so-far, so nothing he sees tells him where he is, and he wins only if he happens to stop exactly at J: chance 1/N. Hiring a candidate at random gets that much anyway.

Checking it

scripts/secretary.mjs reads the film's trials.json and recomputes it: the exact curves at 10, 100 and 1000 candidates, the best cut-offs, the flat top, the table of sizes, and the three runs on the ten cards. Any disagreement stops the build. Then it checks what the film does not show.

The sum, by brute force. Every order of up to 8 candidates is played at every cut-off. The wins, the times he hires nobody, and the whole distribution of the rank he ends up with match the formulas exactly. The wins are compared as whole numbers.

Every order of n candidates, played at every cut-off
nOrdersBest kChance
3610.50000
42410.45833
512020.43333
672020.42778
75,04020.41429
840,32030.40982

No better rule. From the same 40,320 orders and fewer, the script builds every history of relative ranks he could see, and checks facts 1 and 2 of proof three at every node. It then finds the best rule of any kind by working back from the end, and gets the best cut-off's chance every time. The working back of proof three is run for every N up to 1,000 and lands on the step rule's cut-off each time. The step rule itself is checked against the exact curve at every k for every N up to 300.

Simulation. The film's own Monte Carlo is re-checked against the exact sum, and the script runs its own, seeded so the page is the same page every build:

The exact sum against simulations, at 100 candidates
OrdersWorst gap, any cut-offAt k = 37
the film's own (Python, seed 14)200,0001.66 standard errors0.37209
this page's (seed 14)100,0002.52 standard errors0.37364
the exact sum0.37104

Played literally at k=37 over 100,000 orders, that simulation gets the best 0.3726 of the time, hires nobody 0.3711 of the time, and averages rank 20.0. The clock rule is simulated on 60,000 days, each with a random number of candidates from 1 to 200. It wins 0.3718 of the time, against the formula's 0.3697.

What is not checked. The limits, 1/e here and 3.8695 and 0.5802 in the variants, are theorems. The script computes the finite values and checks that they approach them, and the full-information limit is quoted, not derived. Proof three holds for every N; the script checks it in full for N≤8 and by working back up to 1,000. The film's 37.0% for hiring nobody is exact. Its script's 36.9% is the simulated figure, which is fine but not the same thing.

Where this shows up

  • The puzzle's history is tangled. It reached a wide audience through Martin Gardner's Scientific American column in February 1960, and Thomas Ferguson's 1989 paper Who solved the secretary problem? sorts out who did what. Dennis Lindley's 1961 solution is the working-back of proof three.
  • Optimal stopping is the study of when to stop and take what is in front of you. Bruss's odds theorem (2000) solves a whole family of these at once: add up the odds of success from the end, and start taking chances when the total reaches 1. Here the odds of a best-so-far at place i are 1/(i−1), so the sum from the end is 1/(N−1)+1/(N−2)+…, which is Sk read backwards, and the rule is the step rule above.
  • As advice. It is often quoted for flat-hunting or dating. The conditions it needs, best or nothing, no going back, a known number and a random order, rarely all hold, and the variants above show that changing any one of them changes the answer. This page makes no claim that it is good advice.

Try it yourself

1. With three candidates, what is the best cut-off, and how often does it win?

Let one go, and you win half the time. Write the qualities in the order they come, with 3 the best. Of the 6 orders, letting one go wins on 132, 213, 231: 3 of them. Letting nobody or two go wins on two each.

2. Show that he hires nobody exactly k/N of the time.

He hires nobody when nobody after the block beats the best of the block. That happens exactly when the best of the block is the best of all, that is, when the best of all is in the block. The best is equally likely to be in any of the N places, and k of them are in the block.

3. Use the step rule to find the best cut-off for ten candidates, and how far ahead of 4 it is.

S4=1/4+…+1/9=0.9956, which is less than 1, so moving from 3 to 4 loses (1−0.9956)/10≈0.00044. And S3=1/3+…+1/9=1.3290, which is more than 1, so 3 beats 2. The best is 3.

4. By the clock, exactly two candidates come. How often does waiting for 1/e of the day win?

With N=2 the integrand is (1−t)+t·xt=1−t+x, so P2(x)=∫x1(1−t+x)dt=1−x22. At x=1/e that is 1−1/e22, or 43.2%.