Subfactorial — Definition, Formula & Examples
The subfactorial of a non-negative integer , written , is the number of derangements of elements — that is, the number of ways to rearrange items so that no item ends up in its original position.
For a non-negative integer , the subfactorial equals the number of permutations of the set such that for all . It can be computed as , with the convention .
Key Formula
Where:
- = The number of elements being rearranged
- = The factorial of n (total permutations)
- = Index of summation used in the inclusion-exclusion formula
How It Works
To find , start with the total number of permutations and apply the inclusion-exclusion principle to subtract arrangements where at least one element stays fixed. The alternating sum handles the over- and under-counting. As grows, approaches , so roughly of all permutations are derangements. You can also use the recurrence with base cases and .
Worked Example
Problem: Four friends each bring a gift to a party. The gifts are shuffled and handed back randomly. In how many ways can the gifts be distributed so that no one receives their own gift?
Identify n: There are 4 friends, so .
Apply the formula: Compute .
Simplify: Evaluate the expression inside the parentheses, then multiply by 24.
Answer: There are 9 ways to distribute the gifts so that nobody gets their own.
Visualization
Why It Matters
Subfactorials appear in probability problems asking for the chance that no object returns to its original position, such as the classic "hat-check" problem. They also show up in combinatorics courses and competition math, and the underlying inclusion-exclusion technique is widely used in discrete mathematics and computer science.
Common Mistakes
Mistake: Confusing with and assuming all permutations are derangements.
Correction: The factorial counts all permutations, while the subfactorial counts only those where every element moves. For , but .
