Skip to content

Chapter 4: Calculating Coefficient of Generating Functions

(TB1 Ch.3, Article 2)


1. Introduction to Generating Functions

A generating function is a formal power series in which the coefficients encode a sequence.

If a sequence is [ a_0, a_1, a_2, a_3, \dots ]

its ordinary generating function (OGF) is: [ G(x) = a_0 + a_1x + a_2x^2 + a_3x^3 + \cdots ]

In discrete mathematics, we are not concerned with convergence, only with coefficients.


2. Why Generating Functions Are Important

Generating functions allow us to:

  • Count combinatorial objects
  • Solve recurrence relations
  • Model constrained counting problems
  • Extract coefficients systematically

In CS, they appear in:

  • Algorithm analysis
  • Counting paths, strings, trees
  • Recurrences and complexity analysis

3. Coefficient Operator

The notation: [ [x^n]G(x) ] means the coefficient of (x^n) in the generating function (G(x)).


Example

If: [ G(x) = 3 + 5x + 7x^2 + 9x^3 ]

Then:

  • ([x^0]G(x) = 3)
  • ([x^2]G(x) = 7)

4. Standard Generating Functions and Their Coefficients

These are very important for exams.


(a) Geometric Series

[ \frac{1}{1 - x} = 1 + x + x^2 + x^3 + \cdots ]

[ [x^n]\frac{1}{1-x} = 1 ]


(b) Shifted Geometric Series

[ \frac{1}{1 - ax} = 1 + ax + a^2x^2 + a^3x^3 + \cdots ]

[ [x^n]\frac{1}{1-ax} = a^n ]


(c) Power of Geometric Series

[ \frac{1}{(1-x)^k} ]

Coefficient: [ [x^n]\frac{1}{(1-x)^k} = \binom{n+k-1}{k-1} ]


Example

Find the coefficient of (x^4) in: [ \frac{1}{(1-x)^3} ]

[ [x^4] = \binom{4+3-1}{3-1} = \binom{6}{2} = 15 ]


5. Coefficient Extraction Using Algebraic Manipulation

Often, we manipulate generating functions into a known standard form.


Example 1

Find the coefficient of (x^5) in: [ \frac{x^2}{1 - x} ]

Step 1: Rewrite [ \frac{x^2}{1-x} = x^2(1 + x + x^2 + \cdots) ]

Step 2: Expand [ = x^2 + x^3 + x^4 + x^5 + \cdots ]

Answer [ [x^5] = 1 ]


Example 2

Find the coefficient of (x^6) in: [ \frac{x^3}{(1-x)^2} ]

We know: [ \frac{1}{(1-x)^2} = \sum_{n=0}^{\infty} (n+1)x^n ]

So: [ \frac{x^3}{(1-x)^2} = \sum_{n=0}^{\infty} (n+1)x^{n+3} ]

Set: [ n+3 = 6 \Rightarrow n = 3 ]

Coefficient: [ n+1 = 4 ]


6. Coefficient of Product of Generating Functions

If: [ A(x) = \sum a_n x^n,\quad B(x) = \sum b_n x^n ]

Then: [ x^n = \sum_{k=0}^{n} a_k b_{n-k} ]

This is called convolution.


Example

Find the coefficient of (x^3) in: [ (1 + x + x^2)(1 + x + x^2) ]

Expand: [ = 1 + 2x + 3x^2 + 2x^3 + x^4 ]

[ [x^3] = 2 ]


7. Generating Functions for Counting Problems

Example: Number of Solutions

Find the number of non-negative integer solutions to: [ x_1 + x_2 + x_3 = 5 ]

Each variable has generating function: [ 1 + x + x^2 + \cdots = \frac{1}{1-x} ]

Total generating function: [ \left(\frac{1}{1-x}\right)^3 ]

Coefficient: [ [x^5]\frac{1}{(1-x)^3} = \binom{5+3-1}{3-1} = \binom{7}{2} = 21 ]


8. Coefficient with Constraints

Example

Find the number of solutions to: [ x_1 + x_2 + x_3 = 6,\quad x_1 \ge 1 ]

For (x_1 \ge 1): [ x + x^2 + x^3 + \cdots = \frac{x}{1-x} ]

Total generating function: [ \frac{x}{1-x} \cdot \frac{1}{1-x} \cdot \frac{1}{1-x} = \frac{x}{(1-x)^3} ]

Coefficient: [ [x^6]\frac{x}{(1-x)^3} = [x^5]\frac{1}{(1-x)^3} ]

[ = \binom{5+3-1}{2} = \binom{7}{2} = 21 ]


9. General Strategy for Exam Problems

  1. Write the generating function
  2. Convert to a known standard form
  3. Shift powers if needed
  4. Extract coefficient using formula
  5. Clearly show steps

10. Common Exam Mistakes

  • Forgetting power shifts
  • Using wrong binomial coefficient
  • Not identifying correct generating function
  • Algebraic simplification errors

⭐ Exam-Important Formulas (Memorize)

[ \frac{1}{1-x} = \sum x^n ]

[ \frac{1}{(1-x)^k} = \sum \binom{n+k-1}{k-1}x^n ]

[ x^n = \sum_{k=0}^n a_k b_{n-k} ]


Comments