Advanced
combinatorics.
Count Secret Santa draws, group splits, word orders and shares of identical items.
- All orders, n!
- 120
- Share with nothing in place
- 36.6667%
- Long-run share, 1 over e
- 36.7879%
36.67% of all 120 orders leave every item out of its place. That share sits near 36.79% for any group of 4 or more.
Share of orders with nothing in place
D(m) over m factorial for m = 1 to 8: 0%, 50%, 33.3%, 37.5%, 36.7%, 36.8%, and so on. It swings around 36.79% and settles there.
Derangements of m items
| m | D(m) | m! | Share |
|---|---|---|---|
| m = 0 | 1out of 1 | 1 | 100% |
| m = 1 | 0out of 1 | 1 | 0% |
| m = 2 | 1out of 2 | 2 | 50% |
| m = 3 | 2out of 6 | 6 | 33.33% |
| m = 4 | 9out of 24 | 24 | 37.5% |
| m = 5 | 44out of 120 | 120 | 36.67% |
| m = 6 | 265out of 720 | 720 | 36.81% |
| m = 7 | 1,854out of 5,040 | 5,040 | 36.79% |
Working
- 1Start valuesD(0) = 1 and D(1) = 0
- 2Each new item: (m − 1) choices, then two casesD(m) = (m − 1) × (D(m − 1) + D(m − 2))
- 3Step to m = 2D(2) = 1 × (0 + 1) = 1
- 4Step to m = 3D(3) = 2 × (1 + 0) = 2
- 5Step to m = 4D(4) = 3 × (2 + 1) = 9
- 6Step to m = 5D(5) = 4 × (9 + 2) = 44
- 7Check with the second rule, D(n) = n × D(n − 1) ± 15 × 9 − 1 = 44
How it's worked out
Each family answers a different question, so the first step is to pick the one that matches yours. Two things decide it: whether the items are different from each other, and whether the groups or bins have names.
- Derangements, D(n): orders of n items where no item stays in its first place, as in a gift draw where nobody may get their own name.
- Stirling numbers, S(n, k): ways to split n different items into exactly k groups that have no names.
- Bell numbers, B(n): every way to split n different items into groups, with any number of groups.
- Catalan numbers, C(n): strings of n pairs of brackets in which every bracket closes after it opens, and many shapes that match them.
- Multinomial coefficients: orders of n items that come in a few repeated kinds, like the letters of a word.
- Stars and bars: ways to put n identical items into k bins that do have names.
Derangements follow item 1. It moves to one of the m − 1 other places, and the item it displaces either swaps back or does not. OEIS A000166 lists this rule and a second one, D(n) = n × D(n − 1) plus or minus 1, which the tool uses as its check. For 8 items that is 8 × 1,854 + 1 = 14,833.
The NIST Digital Library of Mathematical Functions defines S(n, k) as the number of ways to split the set of n items into exactly k nonempty parts. The newest item either joins one of the k groups already there or starts a group of its own. Adding the row over every k gives the Bell number.
The Catalan formula also has a difference form, the central binomial minus the next one, which the tool uses as its check. The multinomial coefficient can be built one group at a time as a product of binomials. For MISSISSIPPI that product is 1 × 5 × 126 × 55.
Worked examples
Ines runs a Secret Santa for 8 people
Eight names go in a hat and each person draws one. The draw only works if nobody pulls their own name. There are 8 factorial, or 40,320, ways for the names to come out, and 14,833 of them are derangements.
That is 36.79% of draws, so about two draws in three need a redraw. The share hardly moves for a bigger office: it already sits next to 36.79% once there are more than a few people. With 4 people it was 37.5%.
Mr. Okafor splits 6 students into two study groups
The groups have no names and neither may be empty. The count is S(6, 2) = 31. Any split into two groups is fixed once you choose who joins student 1, and every choice except "everyone" works.
If the groups are Team Red and Team Blue, each split can be labeled in 2 ways, so the count doubles to 62. Allow any number of groups and the count is B(6) = 203, of which 1, 31, 90, 65, 15, 1 use 1 to 6 groups.
Ravi orders the letters of MISSISSIPPI
The word has 11 letters: one M, four I, four S and two P. If all 11 were different there would be 39,916,800 orders. Swapping two S letters changes nothing, so each real order was counted many times over.
Dividing by the factorial of each group size removes those repeats, which leaves 34,650 different words.
Reading your result
These numbers grow fast. B(10) is already 115,975, and B(300) runs to hundreds of digits. The tool keeps every digit. Use the significant-figures control when you only need the size, and keep the exact value for a proof or an exam answer.
A derangement share is not a chance unless the draw is fair. The 36.79% figure assumes every order is equally likely. A hat draw does that well. A list made by hand does not.
Names change the answer by k factorial. Stirling numbers treat groups as unnamed, so swapping two whole groups is not new. Named groups multiply the count by the number of ways to hand out the names, which is why 6 students into 2 named teams gives 62 instead of 31.
Catalan numbers count many things. C(3) = 5 is the number of ways to write 3 pairs of brackets, the number of ways to cut a hexagon into triangles, and the number of full binary trees with 4 leaves. C(10) is 16,796.
Common mistakes
- Using stars and bars for different items. Stars and bars needs identical items. Ten different gifts for 4 children is 4 to the power 10, not the 286 ways that 10 identical candies give.
- Using a Stirling number for named teams. If the teams have names or roles, multiply by k factorial.
- Forgetting that "at least one each" is a new count. Give every bin one item first, then share the rest. For 10 candies and 4 children that drops the count to 84.
- Group sizes that do not add up. A multinomial needs every item in exactly one group, so the sizes must add up to n.
Questions people ask
Sources
- OEIS Foundation, A000166, Subfactorial or rencontres numbers, or derangements
- NIST Digital Library of Mathematical Functions, section 26.8, Set Partitions: Stirling Numbers
- NIST Digital Library of Mathematical Functions, section 26.7, Set Partitions: Bell Numbers
- NIST Digital Library of Mathematical Functions, section 26.5, Lattice Paths: Catalan Numbers
- NIST Digital Library of Mathematical Functions, section 26.4, Lattice Paths: Multinomial Coefficients
- Oscar Levin, Discrete Mathematics: An Open Introduction, 3rd ed., section 1.5, Stars and Bars