Lost Boarding Pass
July 21, 2020
We have today a fun little problem from probability:
On a sold-out flight, 100 people line up to board the plane. The first passenger in the line has lost his boarding pass but was allowed in, regardless. He takes a random seat. Each subsequent passenger takes his or her assigned seat if available, or a random unoccupied seat, otherwise. What is the probability that the last passenger to board the plane finds his seat unoccupied?
Your task is to determine the requested probability, either by reasoning mathematically or by writing a program to demonstrate the probability. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
Here’s a solution in Python.
Output:
Here’s a mathematical solution (using 0-indexing) followed by another Python solution.
For any passenger after the initial 0th passenger, the probability that they take the 99th passenger’s seat is the probability that an earlier passenger took their seat times the probability that they take the 99th passenger’s seat from the remaining seats.
The 0th passenger has a 1/100 probability of taking the 99th passenger’s seat.
The 1st passenger has a (1/100 * 1/99 = 1/9900) probability of taking the 99th passenger’s seat, which is the probability that the 0th passenger took the 1st passenger’s seat, times the probability that the 1st passenger takes the 99th passenger’s seat from the 99 remaining seats.
The probability that the 2nd passenger’s seat is taken is (1/100 + 1/9900 = 1/99), the probability that either passenger 0 or passenger 1 is in their seat. Given the inherent symmetry of the problem, 1/100 and 1/9900 are the same probabilities from the earlier calculations above. Since the events are mutually exclusive, the probabilities can be added. Thus, the 2nd passenger has a (1/99 * 1/98 = 1/9702) probability of taking the 99th passenger’s seat, which is the probability that the 0th passenger or 1st passenger took the 2nd passenger’s seat, times the probability that the 2nd passenger takes the 99th passenger’s seat from the 98 remaining seats.
A pattern emerges where for x > 0, the probability that passenger x’s seat is taken is 1/(100 – x + 1), and the the probability that the x’th passenger is in the 99th passenger’s seat is (1/(100 – x + 1))*(1/(100 – x)).
Here’s the corresponding sequence that shows the probability of the x’th passenger being in the 99th passenger’s seat.
Similar reasoning can be used for a different number of initial seats, where 1/2 would still be the resulting probability that the last passenger’s seat is taken.
Here’s a dynamic programming solution in Python. It calculates the sequence described above and returns the last element. The probability of a passenger’s seat being taken is calculated as a cumulative sum from prior elements in the sequence, as I wrote this prior to noticing the pattern above (which permits a simpler program).
Output:
Here’s another version, which utilizes the pattern described in my last post (as opposed to the less efficient dynamic programming approach).
Rather than only returning the probability that the last passenger’s seat is taken, it returns the sequence of probabilities for each passenger being in the last passenger’s seat.
The last value is the probability that the last passenger occupies their own seat (the answer to the question).
Output:
The update from my dynamic programming solution to the solution in my last post was based on a pattern that I noticed, where for x > 0, the probability that passenger x’s seat is taken is 1/(100 – x + 1).
Induction can alternatively be used to prove the following equation, which is a more principled justification for using that formula.
The base case is x = 2, and the inductive step shows that the equation for x = k implies the equation for x = k + 1.