The question
You watch a sequence of random rewards and may stop at most once, collecting the reward in front of you. Rewards you pass up are gone. When should you stop? Interviewers ask this as dice games, card games, house offers and hiring puzzles, and the answer always has the same shape:
Stop when what you have now is at least what you expect to get by continuing optimally.
The quantity on the right is the continuation value. Everything in this lesson is a way of computing it.
A stopping rule may use only what you have seen so far. "Stop at the largest value" is not a rule; "stop at the first value above 0.7" is.
Finite horizon: work backwards
Suppose you will see at most i.i.d. offers and must accept one. Let be the value of the game with offers still to come, playing optimally. With one offer left you must take it, so . With left, you see an offer and compare it with :
The optimal rule is a threshold rule: with offers left (this one included), accept iff . The thresholds fall as the deadline approaches, because the option to keep searching is worth less when there is less time to use it.
For and a threshold , , so
| Offers left | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
slowly: with many offers you can afford to be picky, but each extra offer adds less.
Worked example
three days to sell
You must sell a car within three days. Each day brings one offer, uniform on (in units of $10,000), independent across days. An offer must be accepted or rejected on the day. What is your strategy and its expected sale price?
Show solutionHide solution
Work from the last day.
- Day 3 (one offer left): take whatever comes. Value .
- Day 2 (two left): accept iff . Value .
- Day 1 (three left): accept iff . Value .
So: accept on day 1 only above $6,250, on day 2 above $5,000, and take anything on day 3. Expected price about $6,953, against $5,000 for accepting the first offer.
Notice what the thresholds are: each one is the value of the remaining game. Say that out loud in an interview; it is the whole argument.
The one-step lookahead rule
Some problems have no fixed horizon. A useful shortcut is the one-step lookahead (OLA) rule: stop as soon as stopping now is at least as good as continuing for exactly one more step and then stopping.
OLA is optimal when the problem is monotone: once the "stop now beats one more step" condition holds, it keeps holding whatever happens next. Then there is never a reason to continue past the first state where it holds, because from there on you would stop at the next step anyway.
Dice example. Roll a die repeatedly, adding the faces to a running total. If you roll a 1, the total is wiped out and the game ends with nothing. You may stop at any time and keep the total. With total , one more roll changes your total by
This is positive iff . The total only goes up while you keep rolling (or the game ends), so once the condition holds for ever: the problem is monotone and OLA is optimal. Stop at the first total of 20 or more. An exact calculation over all paths gives an expected payoff of about , and stopping at 20 or at 21 gives the same value, because at exactly 20 you are indifferent.
The secretary problem
candidates arrive in random order. After each interview you know only how the candidate ranks against those already seen, and you must hire or reject on the spot. You win only if you hire the best of all . How do you maximise the chance of winning?
Why a cutoff rule. Only a candidate who is the best so far (a "relative best") can be the overall best. A relative best at position is the overall best with probability , because the best of the first is the best of all exactly when the overall best is among the first . That probability increases with , while the value of continuing decreases with (fewer candidates left). So there is a cutoff: reject the first candidates, then hire the first relative best.
The success probability. Fix the cutoff . You win iff the best candidate is at some position and you have not already hired someone between and . The second condition holds exactly when the best of the first candidates sits among the first (the skipped block), which has probability . So
The limit. Write . The sum is a Riemann sum for , so
Differentiating, , so and .
The rule: skip about of the candidates, then take the first one better than all of them. You win about 37% of the time, however large is.
Exact optimal cutoffs for small :
| Skip | ||
|---|---|---|
| 3 | 1 | |
| 4 | 1 | |
| 5 | 2 | |
| 10 | 3 | |
| 100 | 37 |
The table comes from this script:
from fractions import Fraction
def success(n, r):
"""P(hire the best) when skipping r - 1 candidates."""
if r == 1:
return Fraction(1, n)
return Fraction(r - 1, n) * sum(Fraction(1, i - 1) for i in range(r, n + 1))
for n in (4, 10, 100):
r = max(range(1, n + 1), key=lambda r: success(n, r))
print(n, r - 1, round(float(success(n, r)), 4))
Output:
4 1 0.4583
10 3 0.3987
100 37 0.371
Worked example
the secretary problem with four candidates
Four candidates arrive in random order. Compute the success probability of each cutoff and pick the best.
Show solutionHide solution
Use .
- Skip 0 (): you take the first candidate, who is best with probability .
- Skip 1 (): .
- Skip 2 (): .
- Skip 3 (): (you always take the last candidate).
The best rule skips one candidate. Check by direct reasoning: with you fail only if the first candidate is the best (probability ) or a relative best other than the overall best appears before the best. Enumerating the 24 orders confirms that 11 of them succeed.
Compare : the asymptotic rule says skip one or two, and the exact calculation picks one.
When stopping cannot help
Cards are turned over one at a time from a shuffled deck of 26 red and 26 black. At any moment you may say "next", and you win if the next card is red. Can you beat ?
No. Let be the fraction of red cards among those not yet turned after cards. Given the past, the next card is red with probability , and after it is turned the expected new fraction is again : is a martingale. Your win probability when you say "next" at time is for any stopping rule (the deck is finite, so the optional stopping theorem applies). Waiting until more black cards have gone helps on some paths and hurts on others by exactly the same amount.
The general lesson: a stopping rule cannot create value from a fair game. Stopping helps only when the payoff process is not a martingale, for example when you collect the maximum of something, or when there is a cost, a deadline or a drift. The next lesson develops this.
Knowledge check
In the secretary problem with 10 candidates, which rule maximises the probability of hiring the best one?
Knowledge check
You get two offers, each uniform on , and must accept one of them, deciding on the first before seeing the second. What is the optimal rule and its value?
Knowledge check
You roll a die and add up the faces, but a 1 wipes out the total and ends the game. You may stop and keep the total at any time. When should you stop?
Key takeaways
- Stop iff the current payoff is at least the continuation value; the whole problem is computing that value.
- Finite horizon with i.i.d. offers: , and the threshold with offers left is . For uniform offers, .
- In monotone problems the one-step lookahead rule is optimal; the die-with-a-bust game stops at 20.
- Secretary problem: skip about , then take the first relative best; success probability tends to . Small cases: skip 1 (), skip 3 ().
- No stopping rule beats a martingale: the red-card game is worth exactly .
Practice problems
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).