The Principle of Inclusion and Exclusion (PIE) is a fundamental counting technique used to compute the cardinality of the union of finite sets by correcting for over-counting of elements that belong to multiple sets. It is widely used in combinatorics, probability, and counting problems that arise in computer science and engineering mathematics.
For two finite sets A and B the principle gives:
n(A ∪ B) = n(A) + n(B) - n(A ∩ B)
Here n(X) denotes the number of elements (cardinality) of set X. The formula adds the elements of A and B, then subtracts the elements counted twice - those in A ∩ B.

For three finite sets A, B and C the formula is:
n(A ∪ B ∪ C) = n(A) + n(B) + n(C) - n(A ∩ B) - n(B ∩ C) - n(C ∩ A) + n(A ∩ B ∩ C)
The signs alternate to remove over-counting: single sets are added, pairwise intersections are subtracted, and the triple intersection is added back because it was subtracted three times.

Let A1, A2, ..., An be finite sets. Then
n(A1 ∪ A2 ∪ ... ∪ An) =
Σ n(Ai) - Σ n(Ai ∩ Aj) + Σ n(Ai ∩ Aj ∩ Ak) - ... + (-1)n-1 n(A1 ∩ ... ∩ An)
The first summation runs over all single sets, the second over all distinct pairs, the third over all distinct triples, and so on. The sign of each term is determined by the parity of the size of the intersection.
Every element x that belongs to exactly m of the sets contributes to the right-hand side an amount equal to
Σk=1^{m} (-1)^{k-1} C(m, k) = 1.
Hence the element is counted exactly once on the right-hand side. Summing over all elements yields the formula. The identity above follows from the binomial expansion of (1 - 1)m = 0.
A derangement is a permutation of n distinct objects with no object in its original position. The number of derangements of n objects is denoted by Dn (also called the subfactorial and sometimes written !n).
Use PIE by counting all permutations (n!) and subtracting permutations that fix at least one element.
Dn = n! × [1 - 1/1! + 1/2! - 1/3! + ... + (-1)n 1/n!]
This is an exact formula. As n grows large, Dn is approximately n!/e, and Dn is the nearest integer to n!/e.
The derangement numbers satisfy the recurrence:
Dn = (n - 1) × (Dn-1 + Dn-2)
with initial values D0 = 1 and D1 = 0.
Example 1: Among a group of students, 49 study Physics, 37 study English and 21 study Biology. If 9 of these students study Maths Physics and English, 5 study English and Biology, 4 study Physics and Biology and 3 study Physics, English and Biology, find the number of students in the group.
(a) 91
(b) 92
(c) 86
(d) none of these
Solution.
P represent students who study Physics, E represent students who study English and B represent students who study Biology.
n(P) = 49
n(E) = 37
n(B) = 21
n(P ∩ E) = 9
n(E ∩ B) = 5
n(P ∩ B) = 4
n(P ∩ E ∩ B) = 3
Using PIE for three sets:
n(P ∪ E ∪ B) = n(P) + n(E) + n(B) - n(P ∩ E) - n(E ∩ B) - n(P ∩ B) + n(P ∩ E ∩ B)
n(P ∪ E ∪ B) = 49 + 37 + 21 - 9 - 5 - 4 + 3
n(P ∪ E ∪ B) = 92
Option b is the answer.
Example 2: Find the number of ways that you can put 7 letters into their respective envelopes such that exactly 3 go into the right envelope.
(a) 350
(b) 102
(c) 315
(d) 530
Solution.
Select which 3 letters are placed correctly. The number of ways to choose these 3 is C(7, 3).
C(7, 3) = 7 × 6 × 5 / (1 × 2 × 3) = 35
For the remaining 4 letters, none may be in the correct envelope, so we need the derangement D4.
D4 = 9
Total number of ways = C(7, 3) × D4 = 35 × 9
Total number of ways = 315
Option c is the answer.
Count all permutations of n objects: n!.
Let Ai be the set of permutations fixing element i. A permutation fixes at least one element if it lies in ∪ Ai. Use PIE to exclude permutations fixing one or more elements.
Dn = n! - C(n,1)(n-1)! + C(n,2)(n-2)! - ... + (-1)n C(n,n)(n-n)!.
Factor out n!: Dn = n! × [1 - 1/1! + 1/2! - ... + (-1)n 1/n!].
| 1. What is a derangement in combinatorial mathematics? | ![]() |
| 2. How is the principle of inclusion-exclusion used to count derangements? | ![]() |
| 3. Can you provide an example of how to calculate a derangement using the principle of inclusion-exclusion? | ![]() |
| 4. What is the significance of derangements in real-world applications? | ![]() |
| 5. What are some common misconceptions about derangements? | ![]() |