01 / 21

Inclusion–Exclusion
Principle

Master the art of counting without double-counting. Learn how overlapping sets combine and why simply adding sizes gives the wrong answer.

Discrete Mathematics

Why Counting Gets Tricky

Imagine a class of 30 students. 18 play basketball, 15 play soccer, and 8 play both. How many play at least one sport? If you add \(18 + 15 = 33\), you get more than 30: the 8 students who play both were counted twice.

Sets and Their Sizes

\(|A|\)
The cardinality of set \(A\): how many elements it contains.
\(A \cup B\)
The union: all elements in \(A\), or \(B\), or both.
\(A \cap B\)
The intersection: elements in both \(A\) and \(B\) at the same time.

Visualizing the Overlap

A only B only A ∩ B (overlap) A B Universal set U

The Two-Set Formula

For any two finite sets \(A\) and \(B\):

We include each set's size, then exclude the intersection we double-counted: hence the name inclusion–exclusion.

Extending to Three Sets

A B C A∩B∩C

We add back \(|A \cap B \cap C|\) because it was subtracted too many times in the pairwise step.

The General Pattern

In words: add singles, subtract pairs, add triples, subtract quadruples, and so on, alternating signs. Each term accounts for an over- or under-count from the previous level.

Union vs. Sum

Union \(|A \cup B|\) Simple Sum \(|A| + |B|\)
Counts overlap Once Twice
Result when disjoint \(|A| + |B|\) \(|A| + |B|\)
Result with overlap \(|A| + |B| - |A \cap B|\) Over-counts by \(|A \cap B|\)
When are they equal? Only when \(A \cap B = \emptyset\) (disjoint sets)

How to Apply It

1
Identify your sets. What groups are you counting? Label them \(A, B, C, \ldots\)
2
Find each size. Compute \(|A|, |B|, |C|, \ldots\) individually.
3
Find all intersections. Compute pairwise \(|A \cap B|\), then triples \(|A \cap B \cap C|\), and so on.
4
Alternate signs. Add singles, subtract pairs, add triples, subtract quadruples.
5
Interpret. The result is the size of the union: elements in at least one set.

Example 1: Two-Set Basics

In a group of 50 students, 30 study French and 25 study Spanish. 10 study both. How many study at least one language?

20 10 15 French: 30 Spanish: 25 Outside: 50 − 45 = 5

Example 2: Three-Set Problem

Of 100 people surveyed: 55 like tea, 45 like coffee, 40 like juice. Pairwise overlaps: 20 like tea and coffee, 15 like tea and juice, 10 like coffee and juice. 5 like all three. How many like at least one drink?

Everyone likes at least one drink. The alternating sum accounts perfectly for every overlap level.

Example 3: Complementary Counting

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

1
Singles: \(|A_2| = 50\), \(|A_3| = 33\), \(|A_5| = 20\)
2
Pairs: \(|A_2 \cap A_3| = \lfloor 100/6 \rfloor = 16\), \(|A_2 \cap A_5| = 10\), \(|A_3 \cap A_5| = 6\)
3
Triple: \(|A_2 \cap A_3 \cap A_5| = \lfloor 100/30 \rfloor = 3\)
4
Result: \(50 + 33 + 20 - 16 - 10 - 6 + 3 = 74\)

The Complement Trick

Sometimes it is easier to count what you do not want:

When to use
When the question asks "how many satisfy none" or "how many avoid all" conditions.
Classic example
Derangements: permutations where no element is in its original position. Count via complement.

Real-World Applications

Probability
\(P(A \cup B) = P(A) + P(B) - P(A \cap B)\). Same formula, applied to probabilities instead of counts.
Surveys
Finding how many respondents fit at least one category from overlapping demographic groups.
Computer Science
Counting bit strings, database queries with OR conditions, and Euler's totient function \(\phi(n)\).

Common Mistakes

✕ Forgetting to Subtract
Adding \(|A| + |B|\) without removing \(|A \cap B|\). Always check: do the sets overlap?
✕ Wrong Sign on Triples
For three sets, \(|A \cap B \cap C|\) must be added back (\(+\)), not subtracted again.
✕ Missing an Intersection
With 3 sets you need all 3 pairwise intersections, not just one or two. There are \(\binom{n}{2}\) pairs.

Quick Reference Table

Sets Formula Terms
2 sets \(|A| + |B| - |A \cap B|\) 3
3 sets \(\sum|A_i| - \sum|A_i \cap A_j| + |A \cap B \cap C|\) 7
\(n\) sets \(\displaystyle\sum_{k=1}^{n}(-1)^{k+1}\sum_{|S|=k}\left|\bigcap_{i\in S}A_i\right|\) \(2^n - 1\)

Question 1 of 5

In a class of 40 students, 22 play tennis and 18 play volleyball. 8 play both. How many play at least one sport?

Question 2 of 5

For three sets, after adding \(|A| + |B| + |C|\) and subtracting all pairwise intersections, what must you do with \(|A \cap B \cap C|\)?

Question 3 of 5

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

Question 4 of 5

If \(|A| = 15\), \(|B| = 12\), and \(|A \cup B| = 20\), what is \(|A \cap B|\)?

Question 5 of 5

For \(n\) sets, how many terms appear in the full inclusion–exclusion formula?