Discrete MathematicsPigeonhole, Inclusion-Exclusion and Generating Functions2 of 4
Pigeonhole, Inclusion-Exclusion and Generating Functions · 2

Inclusion-Exclusion with Two and Three Sets

When we count the total number of items across overlapping groups, simply adding the group sizes together counts the shared items more than once.

1

Counting with Two Overlapping Sets

Suppose 10\firstset{10} people in a room play guitar, 8\secondset{8} play piano, and 3\counted{3} play both. We want to find how many people in the room play at least one instrument.

Counting with Two Overlapping Sets
guitar10\htmlClass{lc-blue}{\text{guitar}\enspace 10}
piano8\htmlClass{lc-pink}{\text{piano}\enspace 8}
How many play an instrument?\text{How many play an instrument?}
∣G∣=10\htmlClass{lc-blue}{|G|} = \htmlClass{lc-blue}{10}
∣P∣=8\htmlClass{lc-pink}{|P|} = \htmlClass{lc-pink}{8}
∣G∩P∣=3|\htmlClass{lc-blue}{G} \cap \htmlClass{lc-pink}{P}| = \htmlClass{lc-green}{3}

Adding the two circles gives one tally mark to each outer region, but it puts two tally marks in the middle overlap because people who play both instruments raised their hands twice. Subtracting that overlap once leaves every region with a single tally mark:

∣G∪P⏟either G or P∣\displaystyle |\underbrace{\firstset{G} \cup \secondset{P}}_{\text{either } \firstset{G} \text{ or } \secondset{P}}| =∣G∣+∣P∣−∣G∩P⏟both G and P∣\displaystyle = \firstset{|G|} + \secondset{|P|} - |\underbrace{\firstset{G} \cap \secondset{P}}_{\text{both } \firstset{G} \text{ and } \secondset{P}}|

Note that the vertical bars ∣G∣\firstset{|G|} mean the size (number of elements) of set G\firstset{G}, not absolute value, and in math "either G\firstset{G} or P\secondset{P}" always includes the people who do both. Plugging in the room counts gives the actual number of musicians:

∣G∪P∣\displaystyle |\firstset{G} \cup \secondset{P}| =10+8−3\displaystyle = \firstset{10} + \secondset{8} - \counted{3} =15\displaystyle = 15

So there are 1515 people in the room who play guitar, piano, or both.

2

Three Overlapping Sets and the Tally-Mark Rule

Now let's add a third group, people who play drums (D\thirdset{D}), and find the total number of musicians across all three circles.

Three Overlapping Sets and the Tally-Mark Rule
guitarG\htmlClass{lc-blue}{{\small\text{guitar}}\enspace G}
Ppiano\htmlClass{lc-pink}{P\enspace {\small\text{piano}}}
Ddrums\htmlClass{lc-violet}{D\enspace {\small\text{drums}}}
∣G∪P∪D∣=?|\htmlClass{lc-blue}{G} \cup \htmlClass{lc-pink}{P} \cup \htmlClass{lc-violet}{D}| = \enspace ?

Subtracting all three pair overlaps fixes the two-way regions, but because the center sits inside all three pairs, subtracting them erases the center's three tally marks completely. Adding the three-way overlap back once restores the center's tally mark to 1\counted{1}:

∣G∪P∪D∣=∣G∣+∣P∣+∣D∣⏟singles−(∣G∩P∣+∣G∩D∣+∣P∩D∣)⏟pairs+∣G∩P∩D∣⏟triple\displaystyle \begin{aligned} &|\firstset{G} \cup \secondset{P} \cup \thirdset{D}| \\ &\quad = \underbrace{\firstset{|G|} + \secondset{|P|} + \thirdset{|D|}}_{\text{singles}} \\ &\qquad - \underbrace{(|\firstset{G} \cap \secondset{P}| + |\firstset{G} \cap \thirdset{D}| + |\secondset{P} \cap \thirdset{D}|)}_{\text{pairs}} \\ &\qquad + \underbrace{|\firstset{G} \cap \secondset{P} \cap \thirdset{D}|}_{\text{triple}} \end{aligned}

In the interactive diagram below, subtracting a pair overlap removes a tally mark from both its two-way region and the center, so subtracting all three pairs leaves the center with 00 marks until the triple overlap adds it back.

Each pair overlap covers the center too, so subtracting all three pairs leaves the center empty until the triple overlap adds it back.
3

Filling In a Venn Diagram from the Inside Out

Often a survey problem asks for a specific region of the diagram, like how many students like only one item, or exactly two items, rather than just the total union. Suppose a survey of 100100 students about Chips (C\firstset{C}), Soda (S\secondset{S}), and Pizza (P\thirdset{P}) finds that 50\firstset{50} like Chips, 40\secondset{40} like Soda, 35\thirdset{35} like Pizza, 2020 like Chips and Soda, 1515 like Chips and Pizza, 1010 like Soda and Pizza, and 5\counted{5} like all three. We want to find how many students like only Chips, how many like exactly two snacks, and how many like none.

Filling In a Venn Diagram from the Inside Out
∣U∣=100|U| = 100
Chips\htmlClass{lc-blue}{\text{Chips}}
Soda\htmlClass{lc-pink}{\text{Soda}}
Pizza\htmlClass{lc-violet}{\text{Pizza}}
∣C∣=50∣S∣=40∣P∣=35∣C∩S∣=20∣C∩P∣=15∣S∩P∣=10\begin{alignedat}{3}\htmlClass{lc-blue}{|C|} &= \htmlClass{lc-blue}{50} \quad & \htmlClass{lc-pink}{|S|} &= \htmlClass{lc-pink}{40} \quad & \htmlClass{lc-violet}{|P|} &= \htmlClass{lc-violet}{35} \\[2pt]|\htmlClass{lc-blue}{C} \cap \htmlClass{lc-pink}{S}| &= 20 & |\htmlClass{lc-blue}{C} \cap \htmlClass{lc-violet}{P}| &= 15 & |\htmlClass{lc-pink}{S} \cap \htmlClass{lc-violet}{P}| &= 10\end{alignedat}
∣C∩S∩P∣=5|\htmlClass{lc-blue}{C} \cap \htmlClass{lc-pink}{S} \cap \htmlClass{lc-violet}{P}| = \htmlClass{lc-green}{5}
only Chips=?exactly two=?\text{only Chips} = \enspace ? \qquad \text{exactly two} = \enspace ?
∣U∣=100|U| = 100
Chips ∣C∣=50\htmlClass{lc-blue}{\text{Chips}\ |C|} = \htmlClass{lc-blue}{50}
Soda ∣S∣=40\htmlClass{lc-pink}{\text{Soda}\ |S|} = \htmlClass{lc-pink}{40}
Pizza ∣P∣=35\htmlClass{lc-violet}{\text{Pizza}\ |P|} = \htmlClass{lc-violet}{35}
5\htmlClass{lc-green}{5}
15\htmlClass{lc-green}{15}
10\htmlClass{lc-green}{10}
5\htmlClass{lc-green}{5}
20\htmlClass{lc-green}{20}
15\htmlClass{lc-green}{15}
15\htmlClass{lc-green}{15}
15\htmlClass{lc-green}{15}
Text solution
Subtract the center from each pair overlapRemove the 5\counted{5} students who like all three snacks from each two-circle overlap to find how many like only those two snacks.
Only C and S=20−5=15Only C and P=15−5=10Only S and P=10−5=5\displaystyle \begin{aligned} \text{Only } \firstset{C} \text{ and } \secondset{S} &= 20 - \counted{5} = \counted{15} \\ \text{Only } \firstset{C} \text{ and } \thirdset{P} &= 15 - \counted{5} = \counted{10} \\ \text{Only } \secondset{S} \text{ and } \thirdset{P} &= 10 - \counted{5} = \counted{5} \end{aligned}
Subtract the inner regions from the Chips circle and sum the two-way regionsTake the 50\firstset{50} students in the full Chips circle and remove the three overlap pieces inside it to find "only Chips," then add the three two-way regions for "exactly two snacks."
Only C=50−(15+10+5)=50−30=20Exactly two=15+10+5=30\displaystyle \begin{aligned} \text{Only } \firstset{C} &= \firstset{50} - (\counted{15} + \counted{10} + \counted{5}) \\ &= \firstset{50} - 30 = \counted{20} \\ \text{Exactly two} &= \counted{15} + \counted{10} + \counted{5} = 30 \end{aligned}
Find the union and subtract from the survey totalCombine the singles, pairs, and triple to find how many students like at least one snack, then subtract from 100100 to find who sits outside all three circles.
∣C∪S∪P∣=(50+40+35)−(20+15+10)+5=125−45+5=85\displaystyle \begin{aligned} &|\firstset{C} \cup \secondset{S} \cup \thirdset{P}| \\ &\quad = (\firstset{50} + \secondset{40} + \thirdset{35}) \\ &\qquad - (20 + 15 + 10) + \counted{5} \\ &\quad = 125 - 45 + \counted{5} \\ &\quad = 85 \end{aligned}
None\displaystyle \text{None} =100−85\displaystyle = 100 - 85 =15\displaystyle = \counted{15}

So 20\counted{20} students like only Chips, 3030 like exactly two snacks, 8585 like at least one snack, and 15\counted{15} like none of them.

4

Working Backward to Find the Center

When a problem doesn't give us the center, we can't subtract from the inside out. Instead, we treat the three-set formula as an algebra equation and solve for the missing piece.

Suppose 100100 students are surveyed about three programming languages, Python (P\firstset{P}), Java (J\secondset{J}), and C++ (C\thirdset{C}), and 10\counted{10} students know none of them. Among the students, 55\firstset{55} know Python, 45\secondset{45} know Java, 40\thirdset{40} know C++, 2525 know Python and Java, 2020 know Python and C++, and 1515 know Java and C++. We want to find how many students know all three languages.

Working Backward to Find the Center
∣U∣=25|U| = 25
coffeeC\htmlClass{lc-blue}{{\small\text{coffee}}\enspace C}
Ttea\htmlClass{lc-pink}{T\enspace {\small\text{tea}}}
?\htmlClass{lc-orange}{?}
∣C∣=18∣T∣=12neither=0\htmlClass{lc-blue}{|C|} = \htmlClass{lc-blue}{18} \qquad \htmlClass{lc-pink}{|T|} = \htmlClass{lc-pink}{12} \qquad \text{neither} = \htmlClass{lc-green}{0}
Text solution
Subtract the outsiders to find the unionRemove the 10\counted{10} students who know none of the languages from the 100100 surveyed to find how many are inside at least one circle.
∣P∪J∪C∣\displaystyle |\firstset{P} \cup \secondset{J} \cup \thirdset{C}| =100−10\displaystyle = 100 - \counted{10} =90\displaystyle = 90
Add the single circles and the pair overlapsSum the individual language counts and the two-language overlap counts.
Singles=55+45+40=140Pairs=25+20+15=60\displaystyle \begin{aligned} \text{Singles} &= \firstset{55} + \secondset{45} + \thirdset{40} = 140 \\ \text{Pairs} &= 25 + 20 + 15 = 60 \end{aligned}
Substitute into the Inclusion-Exclusion equation and solve for the center x\offcount{x}Plug the union, singles, and pairs into the three-set formula with x\offcount{x} for the unknown triple overlap.
90=140−60+x90=80+xx=10\displaystyle \begin{aligned} 90 &= 140 - 60 + \offcount{x} \\ 90 &= 80 + \offcount{x} \\ \offcount{x} &= \counted{10} \end{aligned}

So 10\counted{10} students know all three languages, which gives us the center we need if we also want to fill in the remaining regions from the inside out.

5

Counting Multiples and the LCM Trap

When sets are too large to draw by hand, we calculate the size of each circle and overlap first and then plug those counts into the formula. Let's find how many integers from 11 to 100100 are divisible by 2\firstset{2}, 3\secondset{3}, or 5\thirdset{5}, and then see what changes when we count integers from 11 to 100100 divisible by 4\firstset{4}, 6\secondset{6}, or 10\thirdset{10}.

To count how many integers from 11 to 100100 are divisible by a number dd, we divide 100100 by dd and use the floor brackets ⌊100d⌋\lfloor \tfrac{100}{d} \rfloor, which mean we round down to the nearest whole number and drop any remainder.

Counting Multiples and the LCM Trap
How many numbers from 1 to 100\text{How many numbers from 1 to 100}
are divisible by 2, 3, or 5?\text{are divisible by } \htmlClass{lc-blue}{2}\text{, } \htmlClass{lc-pink}{3}\text{, or } \htmlClass{lc-violet}{5}\text{?}
D2\htmlClass{lc-blue}{D_2}
D3\htmlClass{lc-pink}{D_3}
D5\htmlClass{lc-violet}{D_5}
Text solution
Part 1: Integers from 11 to 100100 divisible by 2\firstset{2}, 3\secondset{3}, or 5\thirdset{5}
Divide 100100 by each single divisor and round downCount the multiples of 2\firstset{2}, 3\secondset{3}, and 5\thirdset{5} separately and add them.
⌊1002⌋+⌊1003⌋+⌊1005⌋\displaystyle \firstset{\lfloor \tfrac{100}{2} \rfloor} + \secondset{\lfloor \tfrac{100}{3} \rfloor} + \thirdset{\lfloor \tfrac{100}{5} \rfloor} =50+33+20\displaystyle = \firstset{50} + \secondset{33} + \thirdset{20} =103\displaystyle = 103
Divide 100100 by each pair's least common multipleBecause 2\firstset{2}, 3\secondset{3}, and 5\thirdset{5} share no common factors, numbers divisible by a pair are multiples of 66, 1010, and 1515.
⌊1006⌋+⌊10010⌋+⌊10015⌋\displaystyle \lfloor \tfrac{100}{6} \rfloor + \lfloor \tfrac{100}{10} \rfloor + \lfloor \tfrac{100}{15} \rfloor =16+10+6\displaystyle = 16 + 10 + 6 =32\displaystyle = 32
Divide 100100 by the three-way least common multiple and combineNumbers divisible by all three are multiples of 3030, which we add back after subtracting the pairs.
⌊10030⌋=3∣D2∪D3∪D5∣=103−32+3=74\displaystyle \begin{aligned} \counted{\lfloor \tfrac{100}{30} \rfloor} &= \counted{3} \\ |\firstset{D_2} \cup \secondset{D_3} \cup \thirdset{D_5}| &= 103 - 32 + \counted{3} \\ &= 74 \end{aligned}
So 7474 integers from 11 to 100100 are divisible by 2\firstset{2}, 3\secondset{3}, or 5\thirdset{5}.
Part 2: Integers from 11 to 100100 divisible by 4\firstset{4}, 6\secondset{6}, or 10\thirdset{10}
Divide 100100 by each single divisor and round downCount the multiples of 4\firstset{4}, 6\secondset{6}, and 10\thirdset{10} separately.
⌊1004⌋+⌊1006⌋+⌊10010⌋\displaystyle \firstset{\lfloor \tfrac{100}{4} \rfloor} + \secondset{\lfloor \tfrac{100}{6} \rfloor} + \thirdset{\lfloor \tfrac{100}{10} \rfloor} =25+16+10\displaystyle = \firstset{25} + \secondset{16} + \thirdset{10} =51\displaystyle = 51
Use the least common multiple for each pair overlapBecause 4\firstset{4}, 6\secondset{6}, and 10\thirdset{10} share a factor of 22, their overlaps are multiples of lcm⁡(4,6)=12\operatorname{lcm}(\firstset{4},\secondset{6}) = 12, lcm⁡(4,10)=20\operatorname{lcm}(\firstset{4},\thirdset{10}) = 20, and lcm⁡(6,10)=30\operatorname{lcm}(\secondset{6},\thirdset{10}) = 30 rather than the products 24\offcount{24}, 40\offcount{40}, and 60\offcount{60}.
⌊10012⌋+⌊10020⌋+⌊10030⌋\displaystyle \lfloor \tfrac{100}{12} \rfloor + \lfloor \tfrac{100}{20} \rfloor + \lfloor \tfrac{100}{30} \rfloor =8+5+3\displaystyle = 8 + 5 + 3 =16\displaystyle = 16
Use the three-way least common multiple and combineThe smallest positive integer divisible by 4\firstset{4}, 6\secondset{6}, and 10\thirdset{10} is lcm⁡(4,6,10)=60\operatorname{lcm}(\firstset{4},\secondset{6},\thirdset{10}) = 60, giving one multiple in the center.
⌊10060⌋=1∣D4∪D6∪D10∣=51−16+1=36\displaystyle \begin{aligned} \counted{\lfloor \tfrac{100}{60} \rfloor} &= \counted{1} \\ |\firstset{D_4} \cup \secondset{D_6} \cup \thirdset{D_{10}}| &= 51 - 16 + \counted{1} \\ &= 36 \end{aligned}

So 3636 integers from 11 to 100100 are divisible by 4\firstset{4}, 6\secondset{6}, or 10\thirdset{10}.

On the number grid below, the overlap of any chosen divisors lands on every multiple of their lcm⁡\operatorname{lcm}, which matches the straight product only when the divisors share no common factors and otherwise hits earlier shared multiples that the product skips.

Multiplying divisors together catches every shared multiple when they have no common factors, and skips earlier overlaps when they do.
6

Bit Strings with Locked Slots

Now let's find how many 88-bit strings (strings of eight `0`s and `1`s) either start with `11`, end with `00`, or have `101` in positions 44, 55, and 66.

Here we use the Product Rule to find the size of each group first: once we lock the required bits into their positions, each remaining open slot still has 22 choices (`0` or `1`), giving 2free slots2^{\text{free slots}} possible strings.

Bit Strings with Locked Slots
1\htmlClass{lc-mute}{1}
2\htmlClass{lc-mute}{2}
3\htmlClass{lc-mute}{3}
4\htmlClass{lc-mute}{4}
5\htmlClass{lc-mute}{5}
6\htmlClass{lc-mute}{6}
7\htmlClass{lc-mute}{7}
8\htmlClass{lc-mute}{8}
A\htmlClass{lc-blue}{A}
1\htmlClass{lc-blue}{1}
1\htmlClass{lc-blue}{1}
B\htmlClass{lc-pink}{B}
0\htmlClass{lc-pink}{0}
0\htmlClass{lc-pink}{0}
C\htmlClass{lc-violet}{C}
1\htmlClass{lc-violet}{1}
0\htmlClass{lc-violet}{0}
1\htmlClass{lc-violet}{1}
∣A∪B∪C∣=?|\htmlClass{lc-blue}{A} \cup \htmlClass{lc-pink}{B} \cup \htmlClass{lc-violet}{C}| = \enspace ?
Text solution
Lock one pattern at a time for the singlesCount the open slots out of 88 when we lock `11` at the start (A\firstset{A}, 6\firstset{6} free), `00` at the end (B\secondset{B}, 6\secondset{6} free), or `101` in the middle (C\thirdset{C}, 5\thirdset{5} free).
∣A∣+∣B∣+∣C∣\displaystyle \firstset{|A|} + \secondset{|B|} + \thirdset{|C|} =26+26+25\displaystyle = \firstset{2^6} + \secondset{2^6} + \thirdset{2^5} =64+64+32\displaystyle = \firstset{64} + \secondset{64} + \thirdset{32} =160\displaystyle = 160
Lock two patterns at once for each pair overlapCount the open slots remaining when two restrictions apply at the same time (44 free for A∩B\firstset{A} \cap \secondset{B}, 33 free for A∩C\firstset{A} \cap \thirdset{C}, and 33 free for B∩C\secondset{B} \cap \thirdset{C}).
∣A∩B∣+∣A∩C∣+∣B∩C∣\displaystyle |\firstset{A} \cap \secondset{B}| + |\firstset{A} \cap \thirdset{C}| + |\secondset{B} \cap \thirdset{C}| =24+23+23\displaystyle = 2^4 + 2^3 + 2^3 =16+8+8\displaystyle = 16 + 8 + 8 =32\displaystyle = 32
Lock all three patterns for the center and combineLocking slots 1\firstset{1}–2\firstset{2}, 4\thirdset{4}–6\thirdset{6}, and 7\secondset{7}–8\secondset{8} all at once leaves only slot 33 open (11 free slot).
∣A∩B∩C∣=21=2∣A∪B∪C∣=160−32+2=130\displaystyle \begin{aligned} |\firstset{A} \cap \secondset{B} \cap \thirdset{C}| &= \counted{2^1} = \counted{2} \\ |\firstset{A} \cup \secondset{B} \cup \thirdset{C}| &= 160 - 32 + \counted{2} = 130 \end{aligned}

So 130130 different 88-bit strings match at least one of the three patterns.

In the slot builder below, intersecting bit-string conditions locks all of their required positions at the same time, so the size of each overlap depends only on how many slots remain open.

Combining patterns locks in all their required bits at once, so the number of matching strings depends only on how many slots stay open.
7

Committees and Complementary Counting

What if we are choosing a committee of 44 people from a club of 55 Seniors, 66 Juniors, and 44 Sophomores (1515 people total), and we want every grade to have at least one person on the committee?

Because order doesn't matter in a committee, there are (n4)\binom{n}{4} ways to pick 44 members from a group of nn people. Notice that "at least one Senior and at least one Junior and at least one Sophomore" is an intersection ("and"), not a union ("or"). To use Inclusion-Exclusion, we count the opposite: the "bad" committees where Seniors are missing (A\firstset{A}) or Juniors are missing (B\secondset{B}) or Sophomores are missing (C\thirdset{C}), and subtract that union from the total number of committees.

Committees and Complementary Counting
5 Seniors5\ \text{Seniors}
6 Juniors6\ \text{Juniors}
4 Sophomores4\ \text{Sophomores}
at least one of each grade\text{at least one of each grade}
committees of 4=?\text{committees of 4} = \enspace ?
Text solution
Count all unrestricted 44-person committeesChoose any 44 people from the 1515 club members with no grade rules.
Total committees\displaystyle \text{Total committees} =(154)\displaystyle = \binom{15}{4} =1365\displaystyle = 1365
Count bad committees missing one grade (singles)Pick all 44 members from the remaining two grades when Seniors are left out (10\firstset{10} available), Juniors are left out (9\secondset{9} available), or Sophomores are left out (11\thirdset{11} available).
∣A∣+∣B∣+∣C∣\displaystyle \firstset{|A|} + \secondset{|B|} + \thirdset{|C|} =(104)+(94)+(114)\displaystyle = \firstset{\binom{10}{4}} + \secondset{\binom{9}{4}} + \thirdset{\binom{11}{4}} =210+126+330\displaystyle = \firstset{210} + \secondset{126} + \thirdset{330} =666\displaystyle = 666
Count bad committees missing two or all three grades (pairs and triple)Leaving out two grades forces all 44 members to come from a single grade (44 Sophomores, 66 Juniors, or 55 Seniors), while leaving out all three grades leaves 00 people to choose from.
∣A∩B∣+∣A∩C∣+∣B∩C∣=(44)+(64)+(54)=1+15+5=21∣A∩B∩C∣=0\displaystyle \begin{aligned} &|\firstset{A} \cap \secondset{B}| + |\firstset{A} \cap \thirdset{C}| + |\secondset{B} \cap \thirdset{C}| \\ &\quad = \binom{4}{4} + \binom{6}{4} + \binom{5}{4} \\ &\quad = 1 + 15 + 5 = 21 \\[6pt] &|\firstset{A} \cap \secondset{B} \cap \thirdset{C}| = \counted{0} \end{aligned}
Combine the bad committees and subtract from the totalUse Inclusion-Exclusion to find the total number of committees missing at least one grade, then subtract from 13651365.
∣A∪B∪C∣=666−21+0=645Valid committees=1365−645=720\displaystyle \begin{aligned} |\firstset{A} \cup \secondset{B} \cup \thirdset{C}| &= 666 - 21 + \counted{0} \\ &= 645 \\ \text{Valid committees} &= 1365 - 645 \\ &= 720 \end{aligned}

So 720720 committees have at least one Senior, at least one Junior, and at least one Sophomore.

Key concepts

Inclusion-Exclusion is for counting a union ("either/or", "at least one") when the groups can overlap. Every region in the Venn diagram must end up with a count of 1\counted{1}, which gives the alternating pattern of adding singles, subtracting pairs, and adding back the triple:

∣A∪B∣\displaystyle |\firstset{A} \cup \secondset{B}| =∣A∣+∣B∣−∣A∩B∣\displaystyle = \firstset{|A|} + \secondset{|B|} - |\firstset{A} \cap \secondset{B}|
∣A∪B∪C∣=(∣A∣+∣B∣+∣C∣)−(∣A∩B∣+∣A∩C∣+∣B∩C∣)+∣A∩B∩C∣\displaystyle \begin{aligned} &|\firstset{A} \cup \secondset{B} \cup \thirdset{C}| \\ &\quad = (\firstset{|A|} + \secondset{|B|} + \thirdset{|C|}) \\ &\qquad - (|\firstset{A} \cap \secondset{B}| + |\firstset{A} \cap \thirdset{C}| + |\secondset{B} \cap \thirdset{C}|) \\ &\qquad + |\firstset{A} \cap \secondset{B} \cap \thirdset{C}| \end{aligned}

How you set up a problem depends on what is given and what is asked:

Know the center and want a single region ("only C\firstset{C}", "exactly two")?

You don't need the full Inclusion-Exclusion formula first. Just fill in the diagram from the inside out by subtracting the center from each pair (20−5=1520 - \counted{5} = \counted{15} for only C\firstset{C} and S\secondset{S}). Only set up the algebra equation ∣A∪B∪C∣=Singles−Pairs+x|\firstset{A} \cup \secondset{B} \cup \thirdset{C}| = \text{Singles} - \text{Pairs} + \offcount{x} when the center (or another piece) is unknown.

Counting multiples of a\firstset{a}, b\secondset{b}, or c\thirdset{c} up to NN?

Each group has size ⌊Nd⌋\lfloor \tfrac{N}{d} \rfloor, and each overlap uses the least common multiple lcm⁡(a,b)\operatorname{lcm}(\firstset{a}, \secondset{b}), never a×b\firstset{a} \times \secondset{b} unless the divisors share no common factors (for 4\firstset{4} and 6\secondset{6}, use ⌊100lcm⁡(4,6)⌋=⌊10012⌋=8\lfloor \tfrac{100}{\operatorname{lcm}(\firstset{4},\secondset{6})} \rfloor = \lfloor \tfrac{100}{12} \rfloor = 8, not ⌊10024⌋\offcount{\lfloor \tfrac{100}{24} \rfloor}).

Counting bit strings with pattern rules?

Intersecting conditions locks all of their required slots at once, leaving 2free slots2^{\text{free slots}} strings (locking `11` at the start and `00` at the end of an 88-bit string leaves 44 free slots, so 24=162^4 = 16).

Required to include at least one from every group?

Do not apply Inclusion-Exclusion directly to the valid choices, because "at least one of each" is an "and" statement. Count the complement (the bad choices missing group A\firstset{A} or group B\secondset{B} or group C\thirdset{C}) and subtract from the unrestricted total ((154)−∣A∪B∪C∣\binom{15}{4} - |\firstset{A} \cup \secondset{B} \cup \thirdset{C}| =1365−645=720= 1365 - 645 = 720).

8

Practice

1

In a group of 40 travelers, 26 speak Spanish, 19 speak French, and 8 speak both Spanish and French. How many travelers speak either Spanish or French, and how many speak neither?

First find how many travelers are inside at least one circle before comparing that total to the 4040 travelers in the group.

For travelers who speak either Spanish or French, add the two groups and subtract the overlap once: 26+19−8=37\firstset{26} + \secondset{19} - \counted{8} = 37 (watch out for subtracting the overlap twice to get 26+19−16=29\firstset{26} + \secondset{19} - \offcount{16} = \offcount{29}, which leaves out the 8\counted{8} travelers who speak both; those 8\counted{8} are part of "either Spanish or French"). Subtracting the union from the group total gives the number who speak neither: 40−37=340 - 37 = \counted{3}.
2

A survey of 120 students asks which of three streaming services they use: Alpha, Beta, and Gamma. In total, 65 use Alpha, 50 use Beta, 45 use Gamma, 25 use Alpha and Beta, 20 use Alpha and Gamma, 15 use Beta and Gamma, and 8 use all three. How many students use only Alpha, and how many use exactly two of the services?

Since you know the center (88), start there and subtract 88 from each pair total to get the three two-way regions.

Starting at the center (8\counted{8}) and working outward gives the two-way regions: 25−8=1725 - \counted{8} = \counted{17} (Alpha and Beta only), 20−8=1220 - \counted{8} = \counted{12} (Alpha and Gamma only), and 15−8=715 - \counted{8} = \counted{7} (Beta and Gamma only). Be careful not to treat the given pair numbers 2525, 2020, and 1515 as already excluding the center, which would give 25+20+15=6025 + 20 + 15 = \offcount{60} for "exactly two" or 65−(25+20+8)=12\firstset{65} - (25 + 20 + \counted{8}) = \offcount{12} for "only Alpha." Subtracting the three overlap pieces inside Alpha leaves 65−(17+12+8)=28\firstset{65} - (\counted{17} + \counted{12} + \counted{8}) = \counted{28} students who use only Alpha, and adding the three two-way regions gives the number of students who use exactly two services: 17+12+7=36\counted{17} + \counted{12} + \counted{7} = 36.
3

In a survey of 90 gym members about three classes, Yoga, Spin, and Rowing, 12 members take none of the three classes. Among the members, 48 take Yoga, 42 take Spin, 36 take Rowing, 22 take Yoga and Spin, 18 take Yoga and Rowing, and 15 take Spin and Rowing. How many members take all three classes, and how many take only Yoga?

Use the 1212 members who take none to find the size of the three-circle union first, then set up the Inclusion-Exclusion equation with xx for the center.

The union inside the three circles has 90−12=7890 - \counted{12} = 78 members (watch out for setting the union equal to all 9090 members without subtracting the 12\counted{12} outsiders first, which gives 90=71+x  ⟹  x=1990 = 71 + \offcount{x} \implies \offcount{x} = \offcount{19}). Setting 78=(48+42+36)−78 = (\firstset{48} + \secondset{42} + \thirdset{36}) - {} (22+18+15)+x(22 + 18 + 15) + \offcount{x} gives 78=126−55+x=71+x78 = 126 - 55 + \offcount{x} = 71 + \offcount{x}, so x=7\offcount{x} = \counted{7} members take all three classes. Working outward from the center 7\counted{7}, the two-way regions inside Yoga are 22−7=1522 - \counted{7} = \counted{15} and 18−7=1118 - \counted{7} = \counted{11}, leaving the number of members who take only Yoga as 48−(15+11+7)=15\firstset{48} - (\counted{15} + \counted{11} + \counted{7}) = \counted{15}.
4

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

Count how many integers from 11 to 150150 are divisible by 22, 33, or 55 first, then subtract that union from 150150.

For multiples of 2\firstset{2}, 3\secondset{3}, and 5\thirdset{5}, the singles sum to ⌊1502⌋+⌊1503⌋+⌊1505⌋\firstset{\lfloor \tfrac{150}{2} \rfloor} + \secondset{\lfloor \tfrac{150}{3} \rfloor} + \thirdset{\lfloor \tfrac{150}{5} \rfloor} =75+50+30=155= \firstset{75} + \secondset{50} + \thirdset{30} = 155, the pairs sum to ⌊1506⌋+⌊15010⌋+⌊15015⌋\lfloor \tfrac{150}{6} \rfloor + \lfloor \tfrac{150}{10} \rfloor + \lfloor \tfrac{150}{15} \rfloor =25+15+10=50= 25 + 15 + 10 = 50, and the triple is ⌊15030⌋=5\counted{\lfloor \tfrac{150}{30} \rfloor} = \counted{5}. By Inclusion-Exclusion, 155−50+5=110155 - 50 + \counted{5} = 110 integers are divisible by 2\firstset{2}, 3\secondset{3}, or 5\thirdset{5} (don't stop at 110110, which counts the multiples themselves, and don't subtract the triple 5\counted{5} to get 100\offcount{100}). Subtracting from the 150150 total integers leaves 150−110=40150 - 110 = \counted{40}.
5

How many integers from 1 to 200 are divisible by 6, 8, or 10?

Notice that 66, 88, and 1010 are all even. Find the least common multiple for each overlap instead of multiplying the divisors together.

The singles sum to ⌊2006⌋+⌊2008⌋+⌊20010⌋\firstset{\lfloor \tfrac{200}{6} \rfloor} + \secondset{\lfloor \tfrac{200}{8} \rfloor} + \thirdset{\lfloor \tfrac{200}{10} \rfloor} =33+25+20=78= \firstset{33} + \secondset{25} + \thirdset{20} = 78. Using least common multiples for the pairs (lcm⁡(6,8)=24\operatorname{lcm}(\firstset{6},\secondset{8}) = 24, lcm⁡(6,10)=30\operatorname{lcm}(\firstset{6},\thirdset{10}) = 30, and lcm⁡(8,10)=40\operatorname{lcm}(\secondset{8},\thirdset{10}) = 40) gives ⌊20024⌋+⌊20030⌋+⌊20040⌋\lfloor \tfrac{200}{24} \rfloor + \lfloor \tfrac{200}{30} \rfloor + \lfloor \tfrac{200}{40} \rfloor =8+6+5=19= 8 + 6 + 5 = 19, and for all three lcm⁡(6,8,10)=120\operatorname{lcm}(\firstset{6},\secondset{8},\thirdset{10}) = 120 gives ⌊200120⌋=1\counted{\lfloor \tfrac{200}{120} \rfloor} = \counted{1} (multiplying the divisors directly to get 48\offcount{48}, 60\offcount{60}, 80\offcount{80}, and 480\offcount{480} skips shared multiples and gives 78−9+0=6978 - \offcount{9} + \offcount{0} = \offcount{69}). Combining the counts gives 78−19+1=6078 - 19 + \counted{1} = 60.
6

How many 10-bit strings either start with `000`, end with `11`, or have `010` in positions 5, 6, and 7?

Out of the 1010 bit positions, count how many slots remain open when you apply one, two, or all three patterns at the same time.

Locking one condition at a time leaves 7\firstset{7}, 8\secondset{8}, and 7\thirdset{7} free slots, so the singles sum to 27+28+27=128+256+128=512\firstset{2^7} + \secondset{2^8} + \thirdset{2^7} = \firstset{128} + \secondset{256} + \thirdset{128} = 512 (make sure the exponent is the number of free slots, not the 3\offcount{3}, 2\offcount{2}, and 3\offcount{3} locked slots). Locking pairs of conditions leaves 55, 44, and 55 free slots, giving 25+24+25=32+16+32=802^5 + 2^4 + 2^5 = 32 + 16 + 32 = 80 strings. Locking all three conditions leaves slots 44 and 88 open (22 free slots, so 22=4\counted{2^2} = \counted{4}, not 21=2\offcount{2^1} = \offcount{2}). By Inclusion-Exclusion, the total number of such strings is 512−80+4=436512 - 80 + \counted{4} = 436.
7

A department has 4 physicists, 5 chemists, and 5 biologists (14 scientists total). How many ways can a committee of 4 scientists be chosen so that every field has at least one person on the committee?

Count the opposite: the "bad" committees that are missing all physicists, all chemists, or all biologists, then subtract from the (144)\binom{14}{4} total committees.

There are (144)=1001\binom{14}{4} = 1001 unrestricted committees (avoid picking 11 scientist from each field and 11 from the remaining 1111 to get 4×5×5×11=11004 \times 5 \times 5 \times 11 = \offcount{1100}, which counts every valid committee twice). For bad committees missing at least one field, the singles (missing physicists, chemists, or biologists) sum to (104)+(94)+(94)\firstset{\binom{10}{4}} + \secondset{\binom{9}{4}} + \thirdset{\binom{9}{4}} =210+126+126=462= \firstset{210} + \secondset{126} + \thirdset{126} = 462, the pairs (missing two fields, so all 44 come from one field) sum to (54)+(54)+(44)=5+5+1=11\binom{5}{4} + \binom{5}{4} + \binom{4}{4} = 5 + 5 + 1 = 11, and the triple is 0\counted{0}. This gives 462−11+0=451462 - 11 + \counted{0} = 451 bad committees (don't stop at 451451 or forget to subtract the 1111 pair overlaps), leaving 1001−451=5501001 - 451 = 550.