Last week’s post presented two similar problems, the first being a simpler “standard” probability puzzle, and the second being rather more challenging. Since the first problem was basically just a lead-in to this discussion, I won’t spend time on it here; there are plenty of good descriptions of solutions elsewhere (see here, for example).

The harder second problem asks essentially the same question as discussed in the Deranged Secret Santa post from last year: suppose that n participants in a Secret Santa gift exchange each put a slip of paper with their name on it into a single hat. To determine gift-giving assignments, each participant in turn draws a slip from the hat, replacing it with another if he draws his own name. What is the probability that this procedure “fails,” with the last person to draw finding his own name on the last slip in the hat?

I did some simulation and doodling on this problem last year, with limited success. After revisiting the problem this year, there are a few more concrete and interesting results to report.

First, as usual, the problem has already been solved; the solution by Brian Parsonnet appears as sequence A136300 in the Online Encyclopedia of Integer Sequences. (The sequence is parameterized by the number n of participants, where each integer value of the sequence is the numerator of the corresponding probability with denominator .) However, the given recurrence relation is rather complex, and appears to require time and space to compute.

It turns out that we can solve the problem more simply and efficiently (in quadratic time) by transforming the problem slightly. Note that the statement of the problem does not explicitly specify any particular order in which participants draw slips from the hat. That is, it does not really matter who is the last person to draw; all that we want to know is the probability that the last person– whoever that may be– ends up drawing their own name.

At each turn, then, we can randomize the selection of the next person to draw, without affecting the desired probability. (In the context of last week’s airplane boarding problem, the passengers do not stand in a line; they jostle in a group near the jetway entrance, and each next person to board is selected randomly.) This helps a lot: given total participants, let be the number still waiting to draw, and let be the number waiting to draw whose names have already been drawn. Then the probability that the last person to draw is left with his own name is , where is given by the following recurrence (with apologies for WordPress’s limited LaTeX multi-line formatting):

As the following plot shows, the probability of failure varies approximately as ; the probability for in the original problem is approximately 0.0095018.

Finally, this slight transformation of the problem yields an interesting additional bonus: recall the “warning” given in last year’s post, suggesting that you probably do not want to use this procedure at all for your Secret Santa gift exchange. The problem is that all possible permutations (specifically, all possible derangements) mapping gifters to recipients are not equally likely. Even if you handle the small failure possibility of the last person drawing his own name by starting the whole procedure over, some participants are still more likely to draw certain names than others. (As mentioned last year, the most extreme deviation is near the end of the line, with the last person to draw being nearly twice as likely to draw the next-to-last person as to draw the first person in line. See the Mathematica source code below to calculate these probabilities.)

We can relax that warning a bit, based on the following observation: as in the puzzle solution above, if we modify the procedure slightly by first randomizing the order in which participants draw names… then the resulting random assignment does at least have the nice property that each person is equally likely to draw any other person’s name!

I verified this numerically for using the code below, but I think this follows generally from a simple symmetry argument. However, this is a weaker statement than the stronger claim that all derangements are equally likely, which still does not hold ( is a minimal counterexample).

board[seats_, assigned_, prob_] := Module[ {passenger, s, p}, If[Length[seats] === 1, If[seats === {Length[assigned] + 1}, Return[]]; MapIndexed[ (overall[[#2[[1]], #1]] += prob) &, Append[assigned, First[seats]] ], passenger = Length[assigned] + 1; s = DeleteCases[seats, passenger]; p = 1/Length[s]; Scan[ board[DeleteCases[seats, #], Append[assigned, #], prob*p] &, s ] ] ] n = 10; overall = Table[0, {n}, {n}]; board[Range[n], {}, 1];