Introduction to counting and the pigeonhole principle
Product and sum rules, inclusion-exclusion, the pigeonhole principle (including the generalized form), permutations P(n,r) and combinations C(n,r). A final exam topic, not on this semester's midterm.
Counting starts this week. It is not on this semester’s midterm, it is a final exam topic. But combinatorics is one of the places where the most marks turn on an exam, because the questions are short and the answer is a single number. The point is choosing the right rule to apply. Golden rules:
- “And” multiplies, “or” adds (if the options do not overlap).
- If there is overlap, use inclusion-exclusion: subtract once what you counted twice.
- An “at least one” question is solved with the complement: everything minus the ones with none.
- If order matters it is a permutation, if not a combination. Ask yourself in every question: “are AB and BA different?”
- In the pigeonhole principle, name the box and the object explicitly. Half the marks are in that sentence.
Basic counting rules
Product rule
If a task is done in two consecutive steps, and the first step can be done in ways and the second step (in every case) in ways, the task can be done in ways.
Example: a menu with one of 3 starters, 4 main courses and 2 desserts: menus. If you draw a tree diagram you get 24 leaves.
The most important consequences of the product rule:
- Bit strings of length : .
- Functions from an -element set to an -element set: choices for each element, .
- Subsets of an -element set: each element is either in or out, (the power set of week 4).
Sum rule
If a task is done either in the first way ( options) or in the second way ( options), and there are no common options: . Example: project list A has 12 topics, list B has 9, and there are no common topics. There are ways to choose a topic.
Subtraction rule (inclusion-exclusion)
If there are common options you count them twice, so you subtract them once:
Example. How many 7-bit strings begin with 1 or end with 00?
begin with 1: the remaining 6 bits are free -> 2^6 = 64
end with 00: the remaining 5 bits are free -> 2^5 = 32
both (1....00): the 4 middle bits -> 2^4 = 16
Total: 64 + 32 - 16 = 80
“At least one” and the complement
Example. A 4-character password, where each character is an uppercase letter (26) or a digit (10). How many passwords contain at least one digit?
Counting directly is messy (one digit, two digits, …). With the complement:
PITFALL · Doing “at least one” with the product rule. Computing by “make one position a digit (4 ways), 10 digits for that position, the other 3 positions 36” is wrong: it counts passwords with two digits more than once. The complement method is always safe.
Division rule
If you count every outcome exactly times, you divide the total by . Example: 5 people at a round table. In a straight line it is , but rotations count as the same seating, and each seating was counted 5 times: .
The pigeonhole principle
Principle. If you put (or more) objects into boxes, at least one box has at least two objects.
Proof. Suppose, for contradiction, that k + 1 objects are placed
into k boxes and no box contains more than one object.
Then the total number of objects is at most k * 1 = k.
This contradicts having k + 1 objects. Hence some box contains
at least two objects. ∎
Generalized principle. If you put objects into boxes, some box has at least objects.
Example: in a class of 40 students, at least were born in the same month. Reason: if each month had at most 3 people, the total would be at most .
“At least how many to guarantee?” questions
Recipe: set up the worst case, add one. Grades are 5 letters (A, B, C, D, F). How many students must a class have to guarantee that 5 students got the same grade? Worst case: 4 students of each grade, students and still no 5 the same. One more person: .
General pattern: boxes, if you want of the same, the answer is .
TIP · choose the box correctly. If the question says “two numbers whose difference is divisible by 4”, the boxes are the remainders mod 4. If it says “two numbers whose sum is 10”, the boxes are the pairs . The moment you find the box, the question is over.
Permutations and combinations
Permutation (r-permutation): arranging of distinct objects in order.
Combination (r-combination): choosing of distinct objects without order (a subset).
Connection: . First which objects (combination), then in how many ways you arrange them ().
| Question | Does order matter? | Answer |
|---|---|---|
| A president and a vice president from 9 people | Yes | |
| A team of 4 from 10 people | No | |
| A team of 6 from 10 people | No | |
| The positions of the (three) 1s in a 10-bit string | No |
: choosing 4 people is the same job as choosing the 6 who stay out.
TIP · simplify factorials by hand. There is no calculator. For don’t compute : write and simplify first. , , leaving . The denominator always divides evenly, because the result is a count.
Worked example: restricted ordering
6 people line up, and A and B must be next to each other.
1) Make A and B a single block: [AB] + 4 people = 5 objects
2) Arrange the 5 objects: 5! = 120
3) Inside the block AB or BA: 2
4) Product rule: 2 * 120 = 240
If it asks for A and B not next to each other, use the complement: .
Which rule? Decision order
When you read the question, ask yourself in this order:
- How many steps is it built in? If there are consecutive steps, the product rule.
- Are there separate cases? If it splits into “either this or that”, count each case separately and add.
- Do the cases overlap? If they overlap, subtract the intersection.
- Is there the word “at least” or “at most”? The complement is usually shorter.
- Does the order of the chosen items matter? If it matters, ; if not, .
Worked example. How many of the 5-element subsets of contain 1 or 2?
All 5-element subsets: C(10,5) = 252
Containing neither 1 nor 2 (5 of 8): C(8,5) = 56
Containing at least one (complement): 252 - 56 = 196
Find the same answer with inclusion-exclusion too: containing 1 is , containing 2 is , containing both is . . If you get the same number two ways, write it with confidence. If you have time on the exam, do this cross-check.
Common mistakes
| Wrong idea | The truth |
|---|---|
| Just adding in an overlapping “or” | Inclusion-exclusion: subtract the intersection |
| For divisible by 4 or 6, subtract the multiples of 24 | Subtract the multiples of |
| For “at least one digit”, | Complement: |
| Medal awarding as | Order matters: |
| Team selection as | Order does not matter: |
| in the pigeonhole principle | Round up: |
| in a “to guarantee” question | Worst case is , the answer is |
| Forgetting the after the block method | The order inside the block (AB, BA) is multiplied separately |
Test yourself
Exam-style questions. Solve them on paper first, then reveal the answer.
A license plate consists of 2 letters (26 choices each) followed by 3 digits. How many plates are possible?
Show answer
Product rule: five positions, each independent. .
How many bit strings of length 10 are there? How many of them contain exactly three 1s?
Show answer
2 choices for each bit: . Exactly three 1s: choose which 3 of the 10 positions are 1, order does not matter: .
How many bit strings of length 8 begin with 11 or end with 0?
Show answer
: begins with 11, the remaining 6 bits are free: . : ends with 0: . : begins with 11 and ends with 0, the middle 5 bits are free: . Inclusion-exclusion: .
How many integers from 1 to 500 (inclusive) are divisible by 4 or by 6?
Show answer
Divisible by 4: . Divisible by 6: . Divisible by both = divisible by (not 24!): . Total .
How many people must be in a room to guarantee that at least two of them have first names starting with the same letter (26 letters)?
Show answer
The boxes are letters (26), the objects are people. With 26 people, everyone could start with a different letter. The 27th person must land in a box that is already occupied: .
A drawer contains socks of 5 different colors. How many socks must you take (without looking) to be sure of getting 3 socks of the same color?
Show answer
Worst case: 2 socks of each color, socks in total and still no 3 of the same color. The next sock, whatever its color, brings that color to 3. Generalized pigeonhole: the smallest with is .
A committee of 4 is to be chosen from 7 women and 5 men. How many committees contain exactly 2 women?
Show answer
Two independent choices, product rule: 2 of the 7 women is , 2 of the 5 men is . .
In how many ways can gold, silver and bronze medals be awarded among 8 runners?
Show answer
Order matters (gold ≠ silver), no repetition: a permutation. .
In how many ways can 6 people stand in a row if two particular people, A and B, must stand next to each other?
Show answer
Treat A and B as a single block. Block + 4 people = 5 objects, orderings. Inside the block AB or BA: 2 choices. Total .
Among 100 people, at least how many must have been born on the same day of the week?
Show answer
Generalized pigeonhole: . Reason: if at most 14 people fell on each day, the total would be at most .
Prove that among any 5 integers, there are two whose difference is divisible by 4.
Show answer
Boxes: the remainders mod 4, namely 0, 1, 2, 3 (4 boxes). Objects: the 5 integers. Since , by the pigeonhole principle two numbers, say and , have the same remainder: . Then , that is . ∎ (With 4 numbers the claim can fail: 0, 1, 2, 3.)
Let and . How many functions are there? How many of them are one-to-one?
Show answer
Each element of goes to one of 5 values: . For one-to-one, the values must be distinct: .
Verification: All counts were verified with node both by formula and by generating and counting the possibilities one by one (bit strings, passwords, committees, orderings, functions); the pigeonhole claim was scanned over all 5-element choices from 0-11 (verify/MAT2033/09.mjs).