Counting & Combinatorics

Systematic counting underpins probability, algorithms and security. Learn the sum and product rules, permutations and combinations, arrangements with repetition, the binomial theorem and Pascal's triangle, inclusion–exclusion, the pigeonhole principle, and recurrence relations.

How many test cases cover all configuration options? How long would a brute-force password attack take? How many ways can a sample be drawn for inspection? Combinatorics gives exact answers.

An analogy

Permutations count ways to line people up (order matters); combinations count ways to pick a team (order doesn't).

Rules of counting

Sum rule for either/or choices, product rule for sequences of choices. Draw a decision tree when unsure.

Order and repetition

Decide: does order matter? Is repetition allowed? That picks nʳ, P(n, r), C(n, r) or multiset formulas.

Binomial coefficients

Pascal's triangle C(n, k) = C(n − 1, k − 1) + C(n − 1, k). They appear in the binomial distribution and polynomial expansions.

Recurrences and pigeonhole

Recurrences (Fibonacci, Tower of Hanoi aₙ = 2aₙ₋₁ + 1) describe algorithm costs. Pigeonhole proves collisions must exist (hash tables, birthday problem).

Formulas

Worked example: Selections

Given: 10 candidates

Find: Ways to fill 3 distinct posts; ways to pick a 3-person team.

Answer: 720 and 120

Worked example: Binomial coefficient

Given: (2x + 1)⁵

Find: Coefficient of x³.

Answer: 80

Common mistakes

Applications

Key takeaways

Going further