ArticleslgStudy

mathematics

100 prisoners problem

100 prisoners problem is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand 100 prisoners problem rather than just read about it. In short: 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.

100 prisoners problem — main illustration
100 prisoners problem — illustration

Key takeaways

  • 100 prisoners problem belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect 100 prisoners problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of 100 prisoners problem from memory before moving on to harder problems.

Reference excerpt

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.

Illustrations

100 prisoners problem: Each prisoner has to find their own number in one of 100 drawers, but may open only 50 of the drawers.
Each prisoner has to find their own number in one of 100 drawers, but may open only 50 of the drawers.
100 prisoners problem illustration
100 prisoners problem illustration
100 prisoners problem: Probability distribution of the length of the longest cycle of a random permutation of the numbers 1 to 100. The green area corresponds to the survival probability of the prisoners.
Probability distribution of the length of the longest cycle of a random permutation of the numbers 1 to 100. The green area corresponds to the survival probability of the prisoners.
100 prisoners problem: The harmonic numbers are approximately given by the area under the hyperbola and can therefore be approximated by a logarithm.
The harmonic numbers are approximately given by the area under the hyperbola and can therefore be approximated by a logarithm.

Worked examples

Example 1 — a first encounter with 100 prisoners problem

Start with the simplest possible case. Write down what 100 prisoners problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to 100 prisoners problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about 100 prisoners problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of 100 prisoners problem

In research
100 prisoners problem appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses 100 prisoners problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
100 prisoners problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Permutations, Probability theory paradoxes, Recreational mathematics, so understanding it makes those chapters shorter.
In everyday life
Look for 100 prisoners problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “100 prisoners problem” →

How to study 100 prisoners problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what 100 prisoners problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain 100 prisoners problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is 100 prisoners problem in simple terms?

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.

Why does 100 prisoners problem matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study 100 prisoners problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on 100 prisoners problem.

Tags

  • Permutations
  • Probability theory paradoxes
  • Recreational mathematics

Keep exploring