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 people in a room play guitar, 8 play piano, and 3 play both. We want to find how many people in the room play at least one instrument.
Counting with Two Overlapping Sets
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:
∣either G or PG∪P∣=∣G∣+∣P∣−∣both G and PG∩P∣
Note that the vertical bars ∣G∣ mean the size (number of elements) of set G, not absolute value, and in math "either G or P" always includes the people who do both. Plugging in the room counts gives the actual number of musicians:
∣G∪P∣=10+8−3=15
So there are 15 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), and find the total number of musicians across all three circles.
Three Overlapping Sets and the Tally-Mark Rule
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:
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 0 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 100 students about Chips (C), Soda (S), and Pizza (P) finds that 50 like Chips, 40 like Soda, 35 like Pizza, 20 like Chips and Soda, 15 like Chips and Pizza, 10 like Soda and Pizza, and 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
Text solution
Subtract the center from each pair overlapRemove the 5 students who like all three snacks from each two-circle overlap to find how many like only those two snacks.
Only C and SOnly C and POnly S and P=20−5=15=15−5=10=10−5=5
Subtract the inner regions from the Chips circle and sum the two-way regionsTake the 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 CExactly two=50−(15+10+5)=50−30=20=15+10+5=30
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 100 to find who sits outside all three circles.
∣C∪S∪P∣=(50+40+35)−(20+15+10)+5=125−45+5=85
None=100−85=15
So 20 students like only Chips, 30 like exactly two snacks, 85 like at least one snack, and 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 100 students are surveyed about three programming languages, Python (P), Java (J), and C++ (C), and 10 students know none of them. Among the students, 55 know Python, 45 know Java, 40 know C++, 25 know Python and Java, 20 know Python and C++, and 15 know Java and C++. We want to find how many students know all three languages.
Working Backward to Find the Center
Text solution
Subtract the outsiders to find the unionRemove the 10 students who know none of the languages from the 100 surveyed to find how many are inside at least one circle.
∣P∪J∪C∣=100−10=90
Add the single circles and the pair overlapsSum the individual language counts and the two-language overlap counts.
SinglesPairs=55+45+40=140=25+20+15=60
Substitute into the Inclusion-Exclusion equation and solve for the center xPlug the union, singles, and pairs into the three-set formula with x for the unknown triple overlap.
9090x=140−60+x=80+x=10
So 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 1 to 100 are divisible by 2,3, or 5, and then see what changes when we count integers from 1 to 100 divisible by 4,6, or 10.
To count how many integers from 1 to 100 are divisible by a number d, we divide 100 by d and use the floor brackets ⌊d100⌋, which mean we round down to the nearest whole number and drop any remainder.
Counting Multiples and the LCM Trap
Text solution
Part 1: Integers from 1 to 100 divisible by 2,3, or 5
Divide 100 by each single divisor and round downCount the multiples of 2,3, and 5 separately and add them.
⌊2100⌋+⌊3100⌋+⌊5100⌋=50+33+20=103
Divide 100 by each pair's least common multipleBecause 2,3, and 5 share no common factors, numbers divisible by a pair are multiples of 6,10, and 15.
⌊6100⌋+⌊10100⌋+⌊15100⌋=16+10+6=32
Divide 100 by the three-way least common multiple and combineNumbers divisible by all three are multiples of 30, which we add back after subtracting the pairs.
⌊30100⌋∣D2∪D3∪D5∣=3=103−32+3=74
So 74 integers from 1 to 100 are divisible by 2,3, or 5.
Part 2: Integers from 1 to 100 divisible by 4,6, or 10
Divide 100 by each single divisor and round downCount the multiples of 4,6, and 10 separately.
⌊4100⌋+⌊6100⌋+⌊10100⌋=25+16+10=51
Use the least common multiple for each pair overlapBecause 4,6, and 10 share a factor of 2, their overlaps are multiples of lcm(4,6)=12,lcm(4,10)=20, and lcm(6,10)=30 rather than the products 24,40, and 60.
⌊12100⌋+⌊20100⌋+⌊30100⌋=8+5+3=16
Use the three-way least common multiple and combineThe smallest positive integer divisible by 4,6, and 10 is lcm(4,6,10)=60, giving one multiple in the center.
⌊60100⌋∣D4∪D6∪D10∣=1=51−16+1=36
So 36 integers from 1 to 100 are divisible by 4,6, or 10.
On the number grid below, the overlap of any chosen divisors lands on every multiple of their 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 8-bit strings (strings of eight `0`s and `1`s) either start with `11`, end with `00`, or have `101` in positions 4,5, and 6.
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 2 choices (`0` or `1`), giving 2free slots possible strings.
Bit Strings with Locked Slots
Text solution
Lock one pattern at a time for the singlesCount the open slots out of 8 when we lock `11` at the start (A,6 free), `00` at the end (B,6 free), or `101` in the middle (C,5 free).
∣A∣+∣B∣+∣C∣=26+26+25=64+64+32=160
Lock two patterns at once for each pair overlapCount the open slots remaining when two restrictions apply at the same time (4 free for A∩B,3 free for A∩C, and 3 free for B∩C).
∣A∩B∣+∣A∩C∣+∣B∩C∣=24+23+23=16+8+8=32
Lock all three patterns for the center and combineLocking slots 1–2,4–6, and 7–8 all at once leaves only slot 3 open (1 free slot).
∣A∩B∩C∣∣A∪B∪C∣=21=2=160−32+2=130
So 130 different 8-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 4 people from a club of 5 Seniors, 6 Juniors, and 4 Sophomores (15 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 (4n) ways to pick 4 members from a group of n 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)or Juniors are missing (B)or Sophomores are missing (C), and subtract that union from the total number of committees.
Committees and Complementary Counting
Text solution
Count all unrestricted 4-person committeesChoose any 4 people from the 15 club members with no grade rules.
Total committees=(415)=1365
Count bad committees missing one grade (singles)Pick all 4 members from the remaining two grades when Seniors are left out (10 available), Juniors are left out (9 available), or Sophomores are left out (11 available).
∣A∣+∣B∣+∣C∣=(410)+(49)+(411)=210+126+330=666
Count bad committees missing two or all three grades (pairs and triple)Leaving out two grades forces all 4 members to come from a single grade (4 Sophomores, 6 Juniors, or 5 Seniors), while leaving out all three grades leaves 0 people to choose from.
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 1365.
So 720 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, which gives the alternating pattern of adding singles, subtracting pairs, and adding back the triple:
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", "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=15 for only C and S). Only set up the algebra equation ∣A∪B∪C∣=Singles−Pairs+x when the center (or another piece) is unknown.
Counting multiples of a,b, or c up to N?
Each group has size ⌊dN⌋, and each overlap uses the least common multiple lcm(a,b), never a×b unless the divisors share no common factors (for 4 and 6, use ⌊lcm(4,6)100⌋=⌊12100⌋=8, not ⌊24100⌋).
Counting bit strings with pattern rules?
Intersecting conditions locks all of their required slots at once, leaving 2free slots strings (locking `11` at the start and `00` at the end of an 8-bit string leaves 4 free slots, so 24=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 Aor group Bor group C) and subtract from the unrestricted total ((415)−∣A∪B∪C∣=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?
Watch out for subtracting the overlap twice to get 26+19−16=29, which leaves out the 8 travelers who speak both; those 8 are part of "either Spanish or French".
First find how many travelers are inside at least one circle before comparing that total to the 40 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 (watch out for subtracting the overlap twice to get 26+19−16=29, which leaves out the 8 travelers who speak both; those 8 are part of "either Spanish or French"). Subtracting the union from the group total gives the number who speak neither: 40−37=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?
Be careful not to treat the given pair numbers 25,20, and 15 as already excluding the center, which would give 65−(25+20+8)=12 for "only Alpha."
Since you know the center (8), start there and subtract 8 from each pair total to get the three two-way regions.
Starting at the center (8) and working outward gives the two-way regions: 25−8=17 (Alpha and Beta only), 20−8=12 (Alpha and Gamma only), and 15−8=7 (Beta and Gamma only). Be careful not to treat the given pair numbers 25,20, and 15 as already excluding the center, which would give 25+20+15=60 for "exactly two" or 65−(25+20+8)=12 for "only Alpha." Subtracting the three overlap pieces inside Alpha leaves 65−(17+12+8)=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.
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?
Watch out for setting the union equal to all 90 members without subtracting the 12 outsiders first, which gives 90=71+x⟹x=19.
Use the 12 members who take none to find the size of the three-circle union first, then set up the Inclusion-Exclusion equation with x for the center.
The union inside the three circles has 90−12=78 members (watch out for setting the union equal to all 90 members without subtracting the 12 outsiders first, which gives 90=71+x⟹x=19). Setting 78=(48+42+36)−(22+18+15)+x gives 78=126−55+x=71+x, so x=7 members take all three classes. Working outward from the center 7, the two-way regions inside Yoga are 22−7=15 and 18−7=11, leaving the number of members who take only Yoga as 48−(15+11+7)=15.
4
How many integers from 1 to 150 are not divisible by 2, 3, or 5?
Don't stop at 110, which counts the multiples themselves.
Count how many integers from 1 to 150are divisible by 2,3, or 5 first, then subtract that union from 150.
For multiples of 2,3, and 5, the singles sum to ⌊2150⌋+⌊3150⌋+⌊5150⌋=75+50+30=155, the pairs sum to ⌊6150⌋+⌊10150⌋+⌊15150⌋=25+15+10=50, and the triple is ⌊30150⌋=5. By Inclusion-Exclusion, 155−50+5=110 integers are divisible by 2,3, or 5 (don't stop at 110, which counts the multiples themselves, and don't subtract the triple 5 to get 100). Subtracting from the 150 total integers leaves 150−110=40.
5
How many integers from 1 to 200 are divisible by 6, 8, or 10?
Multiplying the divisors directly to get 48,60,80, and 480 skips shared multiples and gives 78−9+0=69.
Notice that 6,8, and 10 are all even. Find the least common multiple for each overlap instead of multiplying the divisors together.
The singles sum to ⌊6200⌋+⌊8200⌋+⌊10200⌋=33+25+20=78. Using least common multiples for the pairs (lcm(6,8)=24,lcm(6,10)=30, and lcm(8,10)=40) gives ⌊24200⌋+⌊30200⌋+⌊40200⌋=8+6+5=19, and for all three lcm(6,8,10)=120 gives ⌊120200⌋=1 (multiplying the divisors directly to get 48,60,80, and 480 skips shared multiples and gives 78−9+0=69). Combining the counts gives 78−19+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 10 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,8, and 7 free slots, so the singles sum to 27+28+27=128+256+128=512 (make sure the exponent is the number of free slots, not the 3,2, and 3 locked slots). Locking pairs of conditions leaves 5,4, and 5 free slots, giving 25+24+25=32+16+32=80 strings. Locking all three conditions leaves slots 4 and 8 open (2 free slots, so 22=4, not 21=2). By Inclusion-Exclusion, the total number of such strings is 512−80+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?
Avoid picking 1 scientist from each field and 1 from the remaining 11 to get 4×5×5×11=1100, which counts every valid committee twice.This gives 462−11+0=451 bad committees, so don't stop at 451.
Count the opposite: the "bad" committees that are missing all physicists, all chemists, or all biologists, then subtract from the (414) total committees.
There are (414)=1001 unrestricted committees (avoid picking 1 scientist from each field and 1 from the remaining 11 to get 4×5×5×11=1100, which counts every valid committee twice). For bad committees missing at least one field, the singles (missing physicists, chemists, or biologists) sum to (410)+(49)+(49)=210+126+126=462, the pairs (missing two fields, so all 4 come from one field) sum to (45)+(45)+(44)=5+5+1=11, and the triple is 0. This gives 462−11+0=451 bad committees (don't stop at 451 or forget to subtract the 11 pair overlaps), leaving 1001−451=550.