The 100 prisoners problem is a mathematical problem in probability theory and combinatorics. In this problem, 100 numbered prisoners must find their own numbers in one of 100 drawers in order to survive. The rules state that each prisoner may open only 50 drawers and cannot communicate with other prisoners after the first prisoner enters to look in the drawers. If all 100 prisoners manage to find their own numbers, they all survive, but if even one prisoner can't find their number, they all die. The straightforward approach of choosing drawers randomly is statistically hopeless, but there is an algorithm that offers the prisoners a realistic chance of survival. Anna Gál and Peter Bro Miltersen first proposed the problem in 2003.
Problem The 100 prisoners problem has different renditions in the literature. The following version is by Philippe Flajolet and Robert Sedgewick:
The director of a prison offers 100 death row prisoners, who are numbered from 1 to 100, a last chance. A room contains a cupboard with 100 drawers. The director randomly puts one prisoner's number in each closed drawer. The prisoners enter the room, one after another. Each prisoner may open and look into 50 drawers in any order. The drawers are closed again afterwards. If, during this search, every prisoner finds their number in one of the drawers, all prisoners are pardoned. If even one prisoner does not find their number, all prisoners die. Before the first prisoner enters the room, the prisoners may discuss strategy — but may not communicate once the first prisoner enters to look in the drawers. What is the prisoners' best strategy? If every prisoner selects 50 drawers independently and randomly, the probability that a single prisoner finds their number is 50%. The probability that all prisoners find their numbers is the product of the single probabilities, which is (1/2)100 ≈ 0.0000000000000000000000000000008, a vanishingly small number. The situation appears hopeless.
Solution
Strategy There is a strategy that provides for the survival of all the prisoners with probability more than 30%. The key to success is that the prisoners do not have to decide beforehand which drawers to open. Each prisoner can use the information gained from the contents of every drawer they already opened to decide which one to open next. Another important observation is that this way the success of one prisoner is not independent of the success of the other prisoners, because they all depend on the way the numbers are distributed. To describe the strategy, not only the prisoners, but also the drawers, are numbered from 1 to 100; for example, row by row starting with the top left drawer. The strategy is now as follows:
Each prisoner first opens the drawer labeled with their own number. If this drawer contains their number, they are done and were successful. Otherwise, the drawer contains the number of another prisoner, and they next open the drawer labeled with this number. The prisoner repeats steps 2 and 3 until they find their own number, or fail because the number is not found in the first fifty opened drawers. If the prisoner could continue indefinitely this way, they would inevitably loop back to the drawer they started with, forming a permutation cycle (see below). By starting with their own number, the prisoner guarantees they are on the specific cycle of drawers containing their number. The only question is whether any cycle is longer than fifty drawers - and only one cycle can possibly be too long, since at most one can comprise more than half of the total drawers.
Examples The reason this is a promising strategy is illustrated with the following example using 8 prisoners and drawers, whereby each prisoner may open 4 drawers. The prison director has distributed the prisoners' numbers into the drawers in the following fashion:
The prisoners now act as follows:
Prisoner 1 first opens drawer 1 and finds number 7. Then they open drawer 7 and find number 5. Then they open drawer 5, where they find their own number and are successful. Prisoner 2 opens drawers 2, 4, and 8 in this order. In the last drawer they find their own number, 2. Prisoner 3 opens drawers 3 and 6, where they find their own number. Prisoner 4 opens drawers 4, 8, and 2, where they find their own number. This is the same cycle that was encountered by prisoner 2 and will be encountered by prisoner 8. Each of these prisoners will find their own number in the third opened drawer. Prisoners 5 to 7 will also each find their numbers in a similar fashion. In this case, all prisoners find their numbers. This is, however, not always the case. For example, the small change to the numbers of swapping drawers 5 and 8 would cause prisoner 1 to fail after opening 1, 7, 5, and 2 (and not finding their own number):
And in the following arrangement, prisoner 1 opens drawers 1, 3, 7, and 4, at which point they have to stop unsuccessfully:
Indeed, all prisoners except 6 (who succeeds directly) fail.
Permutation representation
The prison director's assignment of prisoner numbers to drawers can mathematically be described as a permutation of the integers 1 to 100. A sequence of numbers which after repeated application of the permutation returns to the first number is called a cycle of the permutation. Every permutation can be decomposed into disjoint cycles, that is, cycles which have no common elements. The permutation of the first example above can be written in cycle notation as
(1 7 5)(2 4 8)(3 6) and thus consists of two cycles of length 3 and one cycle of length 2. The permutation of the third example is accordingly
(1 3 7 4 5 8 2)(6) and consists of a cycle of length 7 and a cycle of length 1. The cycle notation is not unique since a cycle of length l can be written in l different ways depending on the starting number of the cycle. During the opening of the drawers using the above strategy, each prisoner follows a single cycle which always ends with their own number. In the case of eight prisoners, this cycle-following strategy is successful if and only if the length of the longest cycle of the permutation is at most 4. If a permutation contains a cycle of length 5 or more, all prisoners whose numbers lie in such a cycle do not reach their own number within four steps.
Probability of success
… excerpt ends here. Continue reading the full article.





