MathIsimple
DM-10
Course 10

Advanced Counting

Explore powerful counting techniques including inclusion-exclusion, generating functions, and special sequences like Catalan and Stirling numbers.

Learning Objectives
  • Apply inclusion-exclusion principle
  • Count derangements
  • Understand generating functions
  • Solve linear recurrence relations
  • Calculate Catalan numbers
  • Use Stirling numbers

1. Inclusion-Exclusion Principle

Theorem 10.1: Inclusion-Exclusion for Two Sets
AB=A+BAB|A \cup B| = |A| + |B| - |A \cap B|
Theorem 10.2: General Inclusion-Exclusion
i=1nAi=iAii<jAiAj+i<j<kAiAjAk\left|\bigcup_{i=1}^{n} A_i\right| = \sum_{i} |A_i| - \sum_{i<j} |A_i \cap A_j| + \sum_{i<j<k} |A_i \cap A_j \cap A_k| - \cdots
Example: Counting with Inclusion-Exclusion

How many integers from 1 to 1000 are divisible by neither 2, 3, nor 5?

Let A = div by 2, B = div by 3, C = div by 5.

ABC=500+333+20016610066+33=734|A \cup B \cup C| = 500 + 333 + 200 - 166 - 100 - 66 + 33 = 734

Answer: 1000734=2661000 - 734 = 266

2. Derangements

Definition 10.1: Derangement

A derangement is a permutation where no element appears in its original position. The number of derangements of n elements is denoted DnD_n.

Theorem 10.3: Derangement Formula
Dn=n!k=0n(1)kk!=n!(11+12!13!++(1)nn!)D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!} = n! \left(1 - 1 + \frac{1}{2!} - \frac{1}{3!} + \cdots + \frac{(-1)^n}{n!}\right)

3. Generating Functions

Definition 10.2: Ordinary Generating Function

The generating function for sequence a0,a1,a2,a_0, a_1, a_2, \ldots is:

G(x)=n=0anxnG(x) = \sum_{n=0}^{\infty} a_n x^n
Example: Common Generating Functions
  • 11x=1+x+x2+\frac{1}{1-x} = 1 + x + x^2 + \cdots (sequence 1, 1, 1, ...)
  • 1(1x)2=1+2x+3x2+\frac{1}{(1-x)^2} = 1 + 2x + 3x^2 + \cdots (sequence 1, 2, 3, ...)
  • (1+x)n=(nk)xk(1+x)^n = \sum \binom{n}{k} x^k (binomial coefficients)

4. Solving Recurrence Relations

Theorem 10.4: Solving Degree-2 Recurrences

For an=c1an1+c2an2a_n = c_1 a_{n-1} + c_2 a_{n-2}, solve the characteristic equation:

r2c1rc2=0r^2 - c_1 r - c_2 = 0

If roots r1,r2r_1, r_2 are distinct: an=α1r1n+α2r2na_n = \alpha_1 r_1^n + \alpha_2 r_2^n

5. Catalan Numbers

Definition 10.3: Catalan Numbers
Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}

First values: 1,1,2,5,14,42,132,1, 1, 2, 5, 14, 42, 132, \ldots

Example: Things Counted by Catalan Numbers
  • Ways to correctly match n pairs of parentheses
  • Full binary trees with n+1 leaves
  • Ways to triangulate a convex (n+2)-gon
  • Monotonic lattice paths that don't cross the diagonal

Practice Quiz

Advanced Counting Quiz
10
Questions
0
Correct
0%
Accuracy
1
Using inclusion-exclusion, what is AB|A \cup B| if A=30|A| = 30, B=20|B| = 20, and AB=5|A \cap B| = 5?
Easy
Not attempted
2
How many integers from 1 to 100 are divisible by 2 or 3?
Medium
Not attempted
3
A derangement is a permutation where no element is in its original position. How many derangements of 3 elements exist?
Medium
Not attempted
4
What is the generating function for the sequence 1,1,1,1,...1, 1, 1, 1, ...?
Medium
Not attempted
5
The recurrence an=an1+an2a_n = a_{n-1} + a_{n-2} with a0=0,a1=1a_0 = 0, a_1 = 1 defines:
Easy
Not attempted
6
The nn-th Catalan number counts:
Hard
Not attempted
7
What is C3C_3 (the 3rd Catalan number)?
Medium
Not attempted
8
Solve an=2an1a_n = 2a_{n-1} with a0=3a_0 = 3. What is ana_n?
Medium
Not attempted
9
The Stirling number S(n,k)S(n,k) counts:
Hard
Not attempted
10
As n gets large, what fraction of permutations are derangements?
Hard
Not attempted

Frequently Asked Questions

When do I use inclusion-exclusion?

Use it when counting objects that DON'T have certain properties is easier than counting those that DO.

What are generating functions good for?

They transform counting problems into algebraic manipulation—useful for solving recurrences and proving identities.

How do I recognize a Catalan number problem?

Look for: matching parentheses, binary trees, non-crossing partitions, paths below diagonals.