Counting answers "how many ways?" without listing every case. It is the base of probability, password analysis and algorithm analysis.
Sum and product rules
- Sum rule: if one task can be done in m ways or another in n ways, and they cannot both happen, the total is m + n.
- Product rule: if one task has m ways and then another has n ways, the total is m × n.
Example: A password has 2 letters followed by 3 digits. Letters can repeat. Ways = 26 × 26 × 10 × 10 × 10 = 676,000.
Inclusion-exclusion
When cases overlap: |A ∪ B| = |A| + |B| − |A ∩ B|. Counting numbers from 1 to 100 divisible by 2 or 3: 50 + 33 − 16 = 67.
Pigeonhole principle
If n + 1 pigeons are placed in n holes, some hole holds at least two pigeons.
Generalised form: if N objects go into k boxes, some box holds at least ⌈N / k⌉ objects.
Examples:
- Among 13 people, at least two were born in the same month (13 people, 12 months).
- Among 25 students, some 3 share a birth month, since ⌈25 / 12⌉ = 3.
- In any group of 6 numbers, two have the same remainder on division by 5? Only 5 remainders exist, so yes.
Worked example
A drawer has socks of 4 colours. How many socks must you pick to be sure of a matching pair? With 4 colours (boxes), 5 socks (pigeons) guarantee two of one colour.
Common mistakes
- Using the sum rule when both tasks happen (use product).
- Forgetting to subtract the overlap in inclusion-exclusion.
- Reading pigeonhole as "exactly two": it only guarantees at least two.
Practice questions
- State the sum rule and product rule.
- How many 3-digit numbers are there with digits 1 to 5, repeats allowed?
- How many numbers from 1 to 50 are divisible by 3 or 5?
- State the pigeonhole principle.
- How many students must there be to be sure that 4 share the same birth month?
Answers to the practice questions
- Sum: m + n for alternatives. Product: m × n for successive choices.
- 5 × 5 × 5 = 125.
- 16 + 10 − 3 = 23.
- If n + 1 objects go into n boxes, some box has at least two.
- 12 × 3 + 1 = 37.
Sources
- Official BCA syllabus Mathematics Foundations to Computer Science I, course code CC101, Unit II
- Kolman, Busby and Ross, Discrete Mathematical Structures, 6th edition, Pearson
