Skip to main content

8.3 Ordinary Generating Functions & Closed-Form Combinatorial Sequences

πŸ“šModule 08: Combinatorics & Recurrence RelationsTopic 8.3: Ordinary Generating Functions & Combinatorial Sequences⏱️5 min read
🎯High-Yield For:Semester Exams β€’ GATE CSE β€’ Technical Interviews

πŸ’‘ Core Intuition: The 3-Second Mental Model​

🍳 The Everyday Analogy: The Clothesline & The Multi-Compartment Bento Box​

Think of generating functions as a mathematical clothesline:

  1. The Clothesline Metaphor (Herbert Wilf): An infinite sequence of numbers (a0,a1,a2,a3,… )(a_0, a_1, a_2, a_3, \dots) is like an unwieldy pile of clothes on the floor. A Generating Function hangs them up neatly on a clothesline using powers of xx as clothes pegs: G(x)=a0+a1x+a2x2+a3x3+…G(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \dots We don't actually care about "evaluating" xx at a specific numerical value. The polynomial is simply an algebraic display case holding the sequence!
  2. Compressing Infinity into a Compact Fraction: The infinite sequence (1,1,1,1,… )(1, 1, 1, 1, \dots) seems impossible to handle all at once. But in generating function form, it is simply the infinite geometric series: 1+x+x2+x3+β‹―=11βˆ’x1 + x + x^2 + x^3 + \dots = \frac{1}{1 - x} The simple algebraic fraction 11βˆ’x\frac{1}{1 - x} encodes the entire infinite sequence in 5 characters!
  3. Convolution (Multiplying Clotheslines): Multiplying two generating functions A(x)β‹…B(x)A(x) \cdot B(x) automatically cross-multiplies all possible combinations whose index powers add up to nn (xkβ‹…xnβˆ’k=xnx^k \cdot x^{n-k} = x^n). This solves complex coin change, partitioning, and resource distribution problems effortlessly!

πŸ’» Bridging to Computer Science: Z-Transforms, Digital Signal Processing & Counting Paths​

In computer science:

  • Digital Signal Processing (DSP): The Ordinary Generating Function is the exact mathematical counterpart of the Z-Transform (X(z)=βˆ‘x[n]zβˆ’nX(z) = \sum x[n] z^{-n}) used to analyze discrete filters, impulse responses, and stability in control systems.
  • Dynamic Programming Optimization: Generating functions compute closed forms for state transitions that would otherwise require O(n2)O(n^2) DP memoization table filling.
  • Counting Graph Walks: The (i,j)(i, j) entry of (Iβˆ’xA)βˆ’1(I - xA)^{-1} is the generating function for the number of walks of length nn between vertices ii and jj in a network.
  • Formal Language Theory: Regular expressions and context-free grammars convert directly into algebraic generating functions via the Chomsky-SchΓΌtzenberger theorem to count words of length nn.

πŸ“œ Ordinary Generating Functions (OGF) Formalism​

πŸ“–Definition 8.2: Ordinary Generating Functiondefinition

Let (a0,a1,a2,… )=(an)n=0∞(a_0, a_1, a_2, \dots) = (a_n)_{n=0}^\infty be a sequence of real numbers. The Ordinary Generating Function (OGF) of the sequence is the formal power series:

G(x)=βˆ‘n=0∞anxn=a0+a1x+a2x2+a3x3+…G(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \dots

The coefficient of xnx^n in G(x)G(x) is denoted by the operator:

[xn] G(x)=an[x^n] \, G(x) = a_n

Formal Power Series Invariant: In discrete mathematics, we treat G(x)G(x) algebraically within the formal ring R[[x]]\mathbb{R}[[x]]. We do not require G(x)G(x) to converge for any specific real value of xx; the variable xx serves strictly as a positional placeholder.

β˜… Generating Function MethodMultiply xⁿ & SumShift & SubstituteDecomposeExtract [xⁿ]Recurrence Solved!Sequence (aβ‚™)Unknown TermsG(x) = βˆ‘ aβ‚™xⁿPower SeriesG(x) = P(x) / Q(x)Algebraic EquationPartial Fractionsβˆ‘ Aα΅’ / (1 - rα΅’x)ᡏaβ‚™ = [xⁿ] G(x)Exact Closed Form
Transform discrete recurrence into algebraic equation G(x), decompose via partial fractions, and extract [xⁿ].

🧰 The Master Generating Function Toolbox​

Canonical Generating Function Closed Forms

Essential sequence-to-function duals used throughout combinatorial analysis

OGF 1

All-Ones Sequence: (1, 1, 1, 1, ...)

1️⃣

1 / (1 - x) = 1 + x + xΒ² + xΒ³ + ...

Formula: βˆ‘β‚™β‚Œβ‚€^∞ xⁿCoefficients: aβ‚™ = 1 for all n β‰₯ 0
↓Scale by Geometric Ratio a
OGF 2

Geometric Progression: (1, a, aΒ², aΒ³, ...)

πŸ“ˆ

1 / (1 - ax) = 1 + ax + aΒ²xΒ² + aΒ³xΒ³ + ...

Formula: βˆ‘β‚™β‚Œβ‚€^∞ aⁿ xⁿCoefficients: aβ‚™ = aⁿ
↓Differentiate to Introduce Linear Factors
OGF 3

Linear Increment Sequence: (1, 2, 3, 4, ...)

πŸ”’

1 / (1 - x)Β² = 1 + 2x + 3xΒ² + 4xΒ³ + ...

Formula: βˆ‘β‚™β‚Œβ‚€^∞ (n + 1) xⁿCoefficients: aβ‚™ = n + 1
↓Generalize to Arbitrary Integer Exponent k
OGF 4

Extended Negative Binomial (Stars and Bars)

⭐

1 / (1 - x)ᡏ = βˆ‘β‚™β‚Œβ‚€^∞ C(n + k - 1, n) xⁿ

Formula: (1 - x)⁻ᡏ = βˆ‘β‚™β‚Œβ‚€^∞ C(n + k - 1, k - 1) xⁿDirectly generates Stars and Bars allocations for k containers!
⚑Law 8.2: Negative Power Binomial Series Cataloglaw

The standard negative power series expansions frequently tested in competitive examinations:

  1. First-Order Simple Series: (1βˆ’x)βˆ’1=11βˆ’x=1+x+x2+x3+x4+β‹―=βˆ‘n=0∞xn(1 - x)^{-1} = \frac{1}{1 - x} = 1 + x + x^2 + x^3 + x^4 + \dots = \sum_{n=0}^{\infty} x^n (1+x)βˆ’1=11+x=1βˆ’x+x2βˆ’x3+x4βˆ’β‹―=βˆ‘n=0∞(βˆ’1)nxn(1 + x)^{-1} = \frac{1}{1 + x} = 1 - x + x^2 - x^3 + x^4 - \dots = \sum_{n=0}^{\infty} (-1)^n x^n
  2. Second-Order Differentiated Series: (1βˆ’x)βˆ’2=1(1βˆ’x)2=1+2x+3x2+4x3+5x4+β‹―=βˆ‘n=0∞(n+1)xn(1 - x)^{-2} = \frac{1}{(1 - x)^2} = 1 + 2x + 3x^2 + 4x^3 + 5x^4 + \dots = \sum_{n=0}^{\infty} (n + 1) x^n (1+x)βˆ’2=1(1+x)2=1βˆ’2x+3x2βˆ’4x3+5x4βˆ’β‹―=βˆ‘n=0∞(βˆ’1)n(n+1)xn(1 + x)^{-2} = \frac{1}{(1 + x)^2} = 1 - 2x + 3x^2 - 4x^3 + 5x^4 - \dots = \sum_{n=0}^{\infty} (-1)^n (n + 1) x^n
  3. General kk-th Order Negative Binomial (Stars and Bars Generating Function): (1βˆ’x)βˆ’k=1(1βˆ’x)k=βˆ‘n=0∞(n+kβˆ’1n)xn=βˆ‘n=0∞(n+kβˆ’1kβˆ’1)xn(1 - x)^{-k} = \frac{1}{(1 - x)^k} = \sum_{n=0}^{\infty} \binom{n + k - 1}{n} x^n = \sum_{n=0}^{\infty} \binom{n + k - 1}{k - 1} x^n

βš™οΈ Operations on Generating Functions​

Algebraic Transforms on Sequences and OGFs

How operations on generating functions modify their underlying sequence coefficients

βž•

Linear Combination

Superposition
  • Ξ± F(x) + Ξ² G(x) generates the sequence (Ξ± aβ‚™ + Ξ² bβ‚™).
  • Allows term-by-term addition of distinct combinatorial components.
⏩

Right Shifting (Delay)

Index Shifting
  • xᡏ G(x) prepends k leading zeros to the sequence: (0, 0, ..., 0, aβ‚€, a₁, aβ‚‚, ...).
  • Essential for aligning recurrence relation indices during summation.
βœ–οΈ

Convolution (Product)

Multiplicative Cross-Sum
  • F(x) Β· G(x) generates the Cauchy convolution cβ‚™ = βˆ‘β‚–β‚Œβ‚€βΏ aβ‚– bβ‚™β‚‹β‚–.
  • Solves partitioning problems: choosing k items from A and n - k items from B.
πŸ“

Differentiation

Multiplying by n
  • x Β· G'(x) = x βˆ‘β‚™β‚Œβ‚€^∞ n aβ‚™ xⁿ⁻¹ = βˆ‘β‚™β‚Œβ‚€^∞ n aβ‚™ xⁿ.
  • Multiplying the OGF derivative by x scales each coefficient by n: (n aβ‚™).

πŸ”€ Derangements & The Principle of Inclusion-Exclusion​

A derangement is a permutation of nn elements in which no element appears in its original position (Ο€(i)β‰ i\pi(i) \neq i for all 1≀i≀n1 \le i \le n).

πŸ“Theorem 8.6: Closed Form & Recurrences for Derangements (Dβ‚™ or !n)theorem
  1. Exact Closed-Form Formula via Inclusion-Exclusion: Dn=!n=n!βˆ‘k=0n(βˆ’1)kk!=n!(10!βˆ’11!+12!βˆ’13!+β‹―+(βˆ’1)nn!)D_n = !n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!} = n! \left( \frac{1}{0!} - \frac{1}{1!} + \frac{1}{2!} - \frac{1}{3!} + \dots + \frac{(-1)^n}{n!} \right)
  2. First-Order Non-Homogeneous Recurrence: Dn=nDnβˆ’1+(βˆ’1)nforΒ nβ‰₯2,D1=0D_n = n D_{n-1} + (-1)^n \quad \text{for } n \ge 2, \quad D_1 = 0
  3. Second-Order Homogeneous Recurrence: Dn=(nβˆ’1)(Dnβˆ’1+Dnβˆ’2)forΒ nβ‰₯3,D1=0,β€…β€ŠD2=1D_n = (n - 1) (D_{n-1} + D_{n-2}) \quad \text{for } n \ge 3, \quad D_1 = 0, \; D_2 = 1
  4. Asymptotic Probability (nβ†’βˆžn \to \infty): Since βˆ‘k=0∞(βˆ’1)kk!=eβˆ’1\sum_{k=0}^\infty \frac{(-1)^k}{k!} = e^{-1}, the probability that a random permutation is a derangement approaches: lim⁑nβ†’βˆžDnn!=1eβ‰ˆ0.367879(β‰ˆ36.8%)\lim_{n \to \infty} \frac{D_n}{n!} = \frac{1}{e} \approx 0.367879 \quad (\approx 36.8\%)
πŸ“Derangements Reference Table (GATE Essentials)observation
nnDerangements DnD_n (!n!n)Total Permutations n!n!Ratio Dn/n!D_n / n!
1010.0000
2120.5000
3260.3333
49240.3750
5441200.3667
62657200.3681
71,8545,0400.3679

πŸ”„ Solving Recurrence Relations via Generating Functions​

Architecture Flow

The 5-Step Generating Function Recurrence Solver

Universal algebraic pipeline to convert a recurrence relation into an exact closed form

βˆ‘Step 1

Multiply by xⁿ & Sum

Multiply both sides of the recurrence by xⁿ and sum from the recurrence threshold (e.g., n = 1 or n = 2) to ∞.

β†’
Infinite Sum Constructed
πŸ“¦Step 2

Substitute G(x)

Rewrite all summation terms in terms of G(x) = βˆ‘ aβ‚™ xⁿ and the initial conditions (e.g., aβ‚€, a₁).

β†’
Algebraic Equation in G(x)
βš™οΈStep 3

Solve for G(x)

Isolate G(x) as a rational fraction: G(x) = P(x) / Q(x).

β†’
Rational Function G(x)
βœ‚οΈStep 4

Partial Fractions

Factor Q(x) and decompose P(x) / Q(x) into standard partial fractions A / (1 - r₁ x) + B / (1 - rβ‚‚ x).

β†’
Decomposed Summands
🎯Step 5

Extract [xⁿ]

Use standard toolbox expansions to read off the coefficient of xⁿ, giving the exact closed form for aβ‚™!


πŸ“ Step-by-Step Worked Examples​

Example 1: Solving a First-Order Recurrence via Generating Functions​

Problem Statement: Solve the recurrence relation an=3anβˆ’1+2a_n = 3a_{n-1} + 2 for nβ‰₯1n \ge 1 with initial condition a0=1a_0 = 1 using generating functions.

Step-by-Step Solution:

  1. Step 1: Multiply by xnx^n and sum for nβ‰₯1n \ge 1

    βˆ‘n=1∞anxn=3βˆ‘n=1∞anβˆ’1xn+2βˆ‘n=1∞xn\sum_{n=1}^{\infty} a_n x^n = 3 \sum_{n=1}^{\infty} a_{n-1} x^n + 2 \sum_{n=1}^{\infty} x^n
  2. Step 2: Express in terms of G(x)G(x)

    • Left-hand side: βˆ‘n=1∞anxn=G(x)βˆ’a0=G(x)βˆ’1\sum_{n=1}^{\infty} a_n x^n = G(x) - a_0 = G(x) - 1
    • First term on RHS: 3βˆ‘n=1∞anβˆ’1xn=3xβˆ‘n=1∞anβˆ’1xnβˆ’1=3xG(x)3 \sum_{n=1}^{\infty} a_{n-1} x^n = 3x \sum_{n=1}^{\infty} a_{n-1} x^{n-1} = 3x G(x)
    • Second term on RHS: 2βˆ‘n=1∞xn=2(11βˆ’xβˆ’1)=2x1βˆ’x2 \sum_{n=1}^{\infty} x^n = 2 \left( \frac{1}{1 - x} - 1 \right) = \frac{2x}{1 - x}
    • Equating: G(x)βˆ’1=3xG(x)+2x1βˆ’xG(x) - 1 = 3x G(x) + \frac{2x}{1 - x}
  3. Step 3: Solve for G(x)G(x)

    G(x)(1βˆ’3x)=1+2x1βˆ’x=1βˆ’x+2x1βˆ’x=1+x1βˆ’xG(x) (1 - 3x) = 1 + \frac{2x}{1 - x} = \frac{1 - x + 2x}{1 - x} = \frac{1 + x}{1 - x} G(x)=1+x(1βˆ’x)(1βˆ’3x)G(x) = \frac{1 + x}{(1 - x)(1 - 3x)}
  4. Step 4: Partial Fraction Decomposition

    1+x(1βˆ’x)(1βˆ’3x)=A1βˆ’x+B1βˆ’3x\frac{1 + x}{(1 - x)(1 - 3x)} = \frac{A}{1 - x} + \frac{B}{1 - 3x}
    • Multiply by (1βˆ’x)(1βˆ’3x)(1 - x)(1 - 3x): 1+x=A(1βˆ’3x)+B(1βˆ’x)1 + x = A(1 - 3x) + B(1 - x)
    • Set x=1x = 1: 1+1=A(1βˆ’3)+0β€…β€ŠβŸΉβ€…β€Š2=βˆ’2Aβ€…β€ŠβŸΉβ€…β€ŠA=βˆ’11 + 1 = A(1 - 3) + 0 \implies 2 = -2A \implies A = -1
    • Set x=1/3x = 1/3: 1+13=0+B(1βˆ’13)β€…β€ŠβŸΉβ€…β€Š43=23Bβ€…β€ŠβŸΉβ€…β€ŠB=21 + \frac{1}{3} = 0 + B\left(1 - \frac{1}{3}\right) \implies \frac{4}{3} = \frac{2}{3} B \implies B = 2
    • Thus: G(x)=βˆ’11βˆ’x+21βˆ’3xG(x) = -\frac{1}{1 - x} + \frac{2}{1 - 3x}
  5. Step 5: Extract the coefficient of xnx^n

    • By standard toolbox expansions: [xn] 11βˆ’x=1and[xn] 11βˆ’3x=3n[x^n] \, \frac{1}{1 - x} = 1 \quad \text{and} \quad [x^n] \, \frac{1}{1 - 3x} = 3^n
    • Combining terms: an=βˆ’1β‹…(1)+2β‹…(3n)=2β‹…3nβˆ’1a_n = -1 \cdot (1) + 2 \cdot (3^n) = 2 \cdot 3^n - 1

Example 2: The Coin Change Problem​

Problem Statement: Find the generating function for the number of ways to make nn cents using pennies (1Β’), nickels (5Β’), and dimes (10Β’).

Step-by-Step Solution:

  1. Step 1: Express Each Coin's Contribution as an Independent Series

    • Pennies (1Β’): Can use 0,1,2,3,…0, 1, 2, 3, \dots pennies. Generates values 0,1,2,3,…0, 1, 2, 3, \dots: P(x)=1+x1+x2+x3+β‹―=11βˆ’xP(x) = 1 + x^1 + x^2 + x^3 + \dots = \frac{1}{1 - x}
    • Nickels (5Β’): Can use 0,1,2,3,…0, 1, 2, 3, \dots nickels. Generates values 0,5,10,15,…0, 5, 10, 15, \dots: N(x)=1+x5+x10+x15+β‹―=11βˆ’x5N(x) = 1 + x^5 + x^{10} + x^{15} + \dots = \frac{1}{1 - x^5}
    • Dimes (10Β’): Can use 0,1,2,3,…0, 1, 2, 3, \dots dimes. Generates values 0,10,20,30,…0, 10, 20, 30, \dots: D(x)=1+x10+x20+x30+β‹―=11βˆ’x10D(x) = 1 + x^{10} + x^{20} + x^{30} + \dots = \frac{1}{1 - x^{10}}
  2. Step 2: Multiply the Independent Generating Functions

    • By the convolution rule, multiplying the polynomials sums the exponents (xaβ‹…xbβ‹…xc=xa+b+cx^a \cdot x^b \cdot x^c = x^{a+b+c}): G(x)=P(x)β‹…N(x)β‹…D(x)=1(1βˆ’x)(1βˆ’x5)(1βˆ’x10)G(x) = P(x) \cdot N(x) \cdot D(x) = \frac{1}{(1 - x)(1 - x^5)(1 - x^{10})}
    • The number of ways to make nn cents is simply the coefficient [xn] G(x)[x^n] \, G(x).

🎯 Exam & Interview Pitfall Check​

Generating Function ConceptGoverning FormulaCommon Fatal Trap
Coefficient of (1βˆ’x)βˆ’k(1 - x)^{-k}(n+kβˆ’1n)\binom{n + k - 1}{n}Using (nk)\binom{n}{k} (forgetting the extended negative binomial rule)
Sequence (0,1,2,3,… )(0, 1, 2, 3, \dots)x(1βˆ’x)2\frac{x}{(1 - x)^2}Confusing with 1(1βˆ’x)2\frac{1}{(1 - x)^2}, which generates (1,2,3,4,… )(1, 2, 3, 4, \dots)
Right-shifting xkG(x)x^k G(x)(0,…,0,a0,a1,… )(0, \dots, 0, a_0, a_1, \dots)Forgetting that kk leading zeros are prepended
Derangements DnD_nn!βˆ‘k=0n(βˆ’1)kk!n! \sum_{k=0}^n \frac{(-1)^k}{k!}Writing n!/en! / e without rounding or checking small nn (D1=0D_1 = 0)
Coin Change OGF∏11βˆ’xwi\prod \frac{1}{1 - x^{w_i}}Adding generating functions instead of multiplying via convolution
Core Conceptual Questions

Question 1: What sequence is generated by G(x)=x(1βˆ’x)2G(x) = \frac{x}{(1 - x)^2}? Key Focus Points: Recall that 1(1βˆ’x)2=βˆ‘n=0∞(n+1)xn=1+2x+3x2+4x3+…\frac{1}{(1 - x)^2} = \sum_{n=0}^\infty (n + 1) x^n = 1 + 2x + 3x^2 + 4x^3 + \dots. Multiplying by xx right-shifts the entire sequence by 1 place:

x(1βˆ’x)2=x+2x2+3x3+4x4+β‹―=βˆ‘n=0∞nxn\frac{x}{(1 - x)^2} = x + 2x^2 + 3x^3 + 4x^4 + \dots = \sum_{n=0}^{\infty} n x^n

Thus, it generates the natural counting sequence (0,1,2,3,4,… )(0, 1, 2, 3, 4, \dots) where an=na_n = n!

Question 2: Does the radius of convergence of a generating function matter in discrete mathematics? Key Focus Points: No! In combinatorics, generating functions are manipulated as formal power series in the ring R[[x]]\mathbb{R}[[x]]. We only perform algebraic operations (addition, convolution multiplication, formal differentiation, division). Analytic convergence is irrelevant because we never assign a numerical value to xx; xx is merely a coefficient holder.

Common Interview Traps: Architectural Trade-Offs

Trap 1: Forgetting Initial Conditions when Shifting Indices in βˆ‘anxn\sum a_n x^n Why it fails: Writing βˆ‘n=1∞anβˆ’1xn\sum_{n=1}^\infty a_{n-1} x^n as G(x)G(x) is a common error. Factoring out xx gives xβˆ‘n=1∞anβˆ’1xnβˆ’1=xβˆ‘k=0∞akxk=xG(x)x \sum_{n=1}^\infty a_{n-1} x^{n-1} = x \sum_{k=0}^\infty a_k x^k = x G(x). Always factor out powers of xx to match the index of the sequence with the exponent of xx!

Trap 2: Forgetting (1βˆ’x)βˆ’k(1 - x)^{-k} uses (n+kβˆ’1n)\binom{n+k-1}{n}, NOT (nk)\binom{n}{k} Why it fails: (nk)\binom{n}{k} is the standard binomial coefficient for (1+x)n(1 + x)^n. For negative exponents (1βˆ’x)βˆ’k(1 - x)^{-k}, the coefficient is (n+kβˆ’1n)\binom{n + k - 1}{n}. Confusing the two produces incorrect coefficients!

πŸ’¬

Discussion & Doubts