Study guide: Counting
Overview
Counting, or combinatorics, answers “how many?” without listing every case. Two rules, the sum rule and the product rule, cover a surprising amount, and permutations and combinations handle the rest.
The real skill is deciding two things: does order matter, and is repetition allowed? Once those are settled the formula follows.
Key ideas explained
Sum and product rules
If you can do task A in m ways or task B in n ways, and they cannot both happen, there are m + n ways in total. If you do one task and then another, there are m · n ways. When cases overlap, use inclusion–exclusion to avoid counting twice.
Permutations
Ordered arrangements of r items from n: P(n, r) = n! / (n − r)!. Arranging all n gives n!. With repeated items divide by the repeats: the letters of MISSISSIPPI can be arranged in 11! / (4!·4!·2!) = 34,650 ways.
Combinations
Unordered selections: C(n, r) = n! / (r!(n − r)!) = P(n, r) / r!. Useful facts: C(n, r) = C(n, n − r), Pascal's rule C(n, r) = C(n−1, r−1) + C(n−1, r), and each row of Pascal's triangle sums to 2ⁿ. Choosing r items with repetition from n types gives C(n + r − 1, r) (stars and bars).
The pigeonhole principle
If more than k items are placed in k boxes, some box holds at least ⌈items / k⌉ of them. It proves that something must exist without saying which item or box it is.
Worked examples
Order matters or it does not
Problem. From 8 people, choose a 3-person committee. Then count the ways to pick a president, vice-president and treasurer from the 8.
- A committee is unordered: C(8, 3) = 56.
- Officers are ordered, so swapping two people gives a different outcome: P(8, 3) = 8·7·6 = 336.
- Consistency check: 56 committees × 3! orderings = 336.
Answer. 56 committees and 336 ways to assign the three offices.
Repeated letters and the pigeonhole principle
Problem. (a) Arrangements of the letters in LEVEL. (b) The least number of people among 25 who must share a birth month.
- (a) LEVEL has 5 letters with L twice and E twice: 5! / (2!·2!) = 120 / 4 = 30.
- (b) 25 people in 12 month-boxes: ⌈25 / 12⌉ = 3.
Answer. (a) 30 arrangements. (b) At least 3 people share a month.
Enter these same values in the calculator above and compare each step with the working shown here.
Common mistakes to avoid
- Using permutations when order does not matter, or the reverse. Ask whether swapping two chosen items gives a different outcome.
- Adding when you should multiply. “Then” usually means multiply; “or” means add.
- Counting overlapping cases twice without subtracting the overlap.
- Forgetting that 0! = 1 and C(n, 0) = C(n, n) = 1.
Where this shows up in computer science
- Password strength: 8 characters from 62 symbols allow 62⁸ ≈ 2.18 × 10¹⁴ possibilities.
- Classical probability is favorable outcomes over total outcomes, and both are counted combinatorially.
- Counting subsets (2ⁿ) or orderings (n!) shows why brute-force search explodes as inputs grow.
Test yourself
Try each question before opening the answer.
How many 5-card hands can be dealt from a 52-card deck?
C(52, 5) = 2,598,960.
In how many ways can 6 people sit in a row? Around a circular table?
6! = 720 in a row; (6 − 1)! = 120 around a circle, since rotations are the same seating.
How many binary strings of length 10 contain exactly three 1s?
C(10, 3) = 120.