Secretary Problem Colab Notebooks and Teaching Resources
Teaching Resources: Google Colab Notebooks
These materials accompany The Secretary Problem Site. Each notebook combines a short mathematical introduction, the stopping rule, Python code that runs in Google Colab, a reproducible simulation, and suggested exercises. You can read and run the material directly in your browser; you do not need to open a terminal or install Python locally.
The notebooks are written for independent study or classroom use. They use Python’s standard library for mathematics and simulations; optional charts use Matplotlib (already available in Google Colab).
Important: A simulated success rate illustrates the mathematical result but does not establish optimality. Exact formulas or backward induction justify the stopping rules presented here.
Classical secretary problem
Derive the exact finite-(n) probability, find the optimal rejection threshold, simulate uniform random permutations, and compare Monte Carlo outcomes with the theoretical curve.
Last-success problem and Bruss’s odds theorem
Study independent Bernoulli observations, compute the sum-the-odds stopping index, simulate the last-success objective, and compare exact and estimated winning probabilities.
Postdoc problem: selecting the second best
Solve the finite-horizon problem by exact backward induction over relative ranks, then simulate policies using random permutations to validate the success probability.
Full-information secretary problem
Derive the first-stage optimal decision for two and three independent uniform observations; simulate success conditional on the initial value and graph the stop–continue crossover.
Interactive demonstrations on this site
Suggested learning sequence
- Begin with the classical notebook to understand random order, records, and the finite-(n) rejection threshold.
- Use the postdoc notebook to see how changing the target from the best to the second best changes the optimal decisions.
- Compare that relative-rank problem with the full-information notebook, which observes numerical values.
- Study the last-success notebook to learn a different optimal-stopping objective and the sum-the-odds rule.
Reproducibility and mathematical tests
Each notebook uses a fixed random seed in its simulations. You can vary the parameters or the number of trials and compare Monte Carlo frequencies with the exact probabilities.
The site’s source repository also contains automated mathematical regression tests for the reference calculations. Those developer tests are kept separate from these student-facing notebooks.
Sources
The foundational work is described in References. The classical and full-information problems draw on Gilbert and Mosteller (1966), and the last-success model uses Bruss (2000). The postdoc notebook uses the relative-rank model presented on the Variants page.