01 / 20

Inclusion–Exclusion
Applications

Master the art of counting without overcounting. Learn how to combine sets, subtract overlaps, and solve real problems using the inclusion–exclusion principle.

Discrete Math

What is Inclusion–Exclusion?

When we count elements that belong to at least one of several sets, simply adding the set sizes together overcounts elements that appear in more than one set. The inclusion–exclusion principle is a systematic way to correct for this overcounting.

The Overcounting Problem

A only 15 A ∩ B 5 B only 10 A B
\(|A| = 20, |B| = 15, |A \cap B| = 5 \rightarrow |A \cup B| = 20 + 15 - 5 = 30\)

Why Overlaps Matter

Union \(A \cup B\)
Elements in at least one set. This is what we want to count.
Intersection \(A \cap B\)
Elements in both sets. These get double-counted when we add.
Correction
Subtract the intersection once to get the true count of the union.

The Two-Set Formula

1
Include every element of \(A\).
2
Include every element of \(B\).
3
Exclude elements in both \(A\) and \(B\) (they were counted twice).

The Three-Set Formula

A B C
\(A \cap B\)
\(A \cap C\)
\(B \cap C\)
\(A \cap B \cap C\)

The General Formula

For \(n\) sets, sum over all possible non-empty subsets of the collection. Subsets of odd size are added, subsets of even size are subtracted.

Inclusion–Exclusion vs. Addition Rule

Inclusion–Exclusion Simple Addition
When to use Sets may overlap Sets are disjoint
Formula (\(n=2\)) \(|A|+|B|-|A\cap B|\) \(|A|+|B|\)
Overlap term Must subtract Zero (not needed)
Risk if misused Undercount if you forget higher overlaps Overcount if sets share elements

Step-by-Step Method

1
Identify the sets. What are the categories you are counting?
2
Count each set individually: find \(|A|\), \(|B|\), \(|C|\), etc.
3
Count all pairwise intersections: \(|A \cap B|\), \(|A \cap C|\), \(|B \cap C|\).
4
Count higher-order intersections if \(n \ge 3\): \(|A \cap B \cap C|\), etc.
5
Apply the formula with alternating signs: add singles, subtract pairs, add triples.

Example 1: Survey Problem

In a class of 40 students: 25 study math, 20 study physics, and 10 study both. How many study at least one subject?

15 10 10 Math (25) Physics (20)

Example 2: Divisibility

How many integers from 1 to 100 are divisible by 2, 3, or 5?

1
Let \(A\) = multiples of 2, \(B\) = multiples of 3, \(C\) = multiples of 5.
2
\(|A|=50\), \(|B|=33\), \(|C|=20\).
3
\(|A\cap B|=16\), \(|A\cap C|=10\), \(|B\cap C|=6\), \(|A\cap B\cap C|=3\).

Example 3: Complement Counting

A common technique: count what you don't want and subtract from the total. How many surjections (onto functions) from a 4-element set to a 3-element set?

1
Total functions: \(3^4 = 81\).
2
Let \(A_i\) = functions that miss element \(i\) in the codomain. Then \(|A_i| = 2^4 = 16\).
3
\(|A_i \cap A_j| = 1^4 = 1\), and \(|A_1 \cap A_2 \cap A_3| = 0\).

Application: Euler's Totient \(\phi(n)\)

\(\phi(n)\) counts integers from 1 to \(n\) that are coprime to \(n\). Inclusion–exclusion gives us the formula directly. Find \(\phi(30)\):

1
Prime factors: \(30 = 2 \times 3 \times 5\). Let \(A,B,C\) = multiples of 2, 3, 5.
2
\(|A|=15\), \(|B|=10\), \(|C|=6\), \(|A\cap B|=5\), \(|A\cap C|=3\), \(|B\cap C|=2\), \(|A\cap B\cap C|=1\).
3
\(|A \cup B \cup C| = 15+10+6-5-3-2+1 = 22\).

Application: Derangements \(D_n\)

A derangement is a permutation where no element stays in its original position. Let \(A_i\) = permutations where element \(i\) is fixed. By inclusion–exclusion:

\(D_3 = 2\)
Of 6 permutations, only 2 have no fixed points.
\(D_4 = 9\)
Of 24 permutations, 9 are derangements.
\(D_5 = 44\)
Of 120 permutations, 44 are derangements.

Common Mistakes to Avoid

✕ Forgetting Higher Overlaps
With 3+ sets, subtracting pairwise overlaps but forgetting to add back the triple intersection.
✕ Wrong Sign Pattern
The signs alternate: +, -, +, -. Mixing up whether pairs are added or subtracted.
✕ Miscounting Intersections
For divisibility, \(|A \cap B|\) = multiples of \(\text{lcm}(a,b)\), not multiples of \(a \cdot b\) when they share factors.

Summary Table

Sets Formula Terms
\(n = 2\) \(|A|+|B|-|A \cap B|\) 3
\(n = 3\) \(+\text{singles}-\text{pairs}+\text{triple}\) 7
\(n = 4\) \(+\text{singles}-\text{pairs}+\text{triples}-\text{quad}\) 15
General \(n\) Alternating sum over all subsets \(2^n - 1\)

Question 1 of 5

In a group of 100 people, 60 like coffee, 45 like tea, and 20 like both. How many like at least one of the two?

Question 2 of 5

How many integers from 1 to 60 are divisible by 2 or 3?

Question 3 of 5

For three sets where \(|A|=10\), \(|B|=12\), \(|C|=8\), \(|A \cap B|=4\), \(|A \cap C|=3\), \(|B \cap C|=2\), and \(|A \cap B \cap C|=1\), what is \(|A \cup B \cup C|\)?

Question 4 of 5

In the inclusion–exclusion formula for \(n\) sets, what sign is applied to terms involving intersections of exactly 4 sets?

Question 5 of 5

What is the number of derangements of 4 elements, \(D_4\)?