Generating Functions

224 words
1 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Generating Functions ## 4.1 Intuition: Encoding Sequences as Power Series A generating function wraps an entire sequence into a single algebraic expression. Operations on the series translate to operations on the sequence.

Generating Functions

4.1 Intuition: Encoding Sequences as Power Series

A generating function wraps an entire sequence into a single algebraic expression. Operations on the series translate to operations on the sequence.
🔑 Key Insight: Generating functions turn combinatorial problems into algebra problems.

4.2 Ordinary Generating Functions (OGF)

For sequence {an}\{a_n\}: G(x)=∑n=0∞anxnG(x) = \sum_{n=0}^\infty a_n x^n

Key OGFs

  • ∑n=0∞xn=11−x\sum_{n=0}^\infty x^n = \frac{1}{1-x}
  • ∑n=0∞(n+k−1k−1)xn=1(1−x)k\sum_{n=0}^\infty \binom{n+k-1}{k-1} x^n = \frac{1}{(1-x)^k}
  • ∑n=0∞nxn=x(1−x)2\sum_{n=0}^\infty n x^n = \frac{x}{(1-x)^2}
  • ∑n=0∞(mn)xn=(1+x)m\sum_{n=0}^\infty \binom{m}{n} x^n = (1+x)^m

4.3 Using OGF to Solve Recurrences

Example: Fibonacci Fn=Fn−1+Fn−2F_n = F_{n-1} + F_{n-2} Let G(x)=∑FnxnG(x) = \sum F_n x^n. G(x)=F0+F1x+∑n=2∞(Fn−1+Fn−2)xnG(x) = F_0 + F_1 x + \sum_{n=2}^\infty (F_{n-1} + F_{n-2}) x^n =0+x+x∑n=1∞Fnxn+x2∑n=0∞Fnxn= 0 + x + x\sum_{n=1}^\infty F_n x^n + x^2\sum_{n=0}^\infty F_n x^n =x+xG(x)+x2G(x)= x + x G(x) + x^2 G(x) G(x)(1−x−x2)=xG(x)(1 - x - x^2) = x G(x)=x1−x−x2G(x) = \frac{x}{1-x-x^2}

4.4 Exponential Generating Functions (EGF)

E(x)=∑n=0∞anxnn!E(x) = \sum_{n=0}^\infty a_n \frac{x^n}{n!} EGF is natural for labeled structures (permutations, sets).

✅ Practice Questions

Q1: Find the OGF for an=2na_n = 2^n.
Solution
G(x)=∑2nxn=∑(2x)n=11−2xG(x) = \sum 2^n x^n = \sum (2x)^n = \frac{1}{1-2x}. Q2: Find the coefficient of x5x^5 in (1−x)−3(1-x)^{-3}. Solution
(1−x)−3=∑(n+22)xn(1-x)^{-3} = \sum \binom{n+2}{2} x^n. Coefficient of x5x^5: (72)=21\binom{7}{2} = 21. Join Discord PreviousRecurrence ApplicationsNextGraph Theory Basics
Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.