VOOZH about

URL: https://www.geeksforgeeks.org/engineering-mathematics/discrete-maths-generating-functions-introduction-prerequisites/

⇱ Generating Functions - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Generating Functions

Last Updated : 3 Jun, 2026

A generating function is a way to represent a sequence of numbers using a power series. In this series, the coefficients of powers of x represent the terms of the sequence. Generating functions make it easier to solve problems related to sequences, counting, and recurrence relations.

The general form of a generating function is shown below,

👁 s_no_2

Basic Prerequisites

Before learning generating functions, we need to understand some basic combinatorics concepts.

1. Permutation: An arrangement of objects where the order matters. It tells us how many different ways we can arrange k objects from n distinct objects.

Number of ways to arrange k objects from n objects:

2. Combination: A selection of objects where the order does not matter. It tells us how many ways we can choose k objects from n distinct objects.

Number of ways to choose k objects from n objects:

Important Generating Functions

The following table shows some important generating functions and their corresponding sequences. These standard results are frequently used to solve combinatorial and recurrence relation problems.

👁 s_no_

Types of Generating Functions

1. Ordinary Generating Function (OGF)

A generating function in which the coefficients of powers of x represent the terms of a sequence. It is mainly used in counting problems and combinatorics.

Formula:

2. Exponential Generating Function (EGF)

A generating function where each term of the sequence is divided by n!. It is commonly used in permutation and arrangement problems where order matters.

Formula:

3. Dirichlet Generating Function (DGF)

A generating function used mainly in number theory, where the terms are divided by ns, with s being a complex variable.

Formula:

4. Probability Generating Function (PGF)

A generating function used in probability theory to represent the probability distribution of a discrete random variable.

Formula:

Solved Examples

Example 1: Find the generating function for the sequence {1, 1, 1, 1, …}.

Solution:

The generating function is

G(x) = 1 + x + x² + x³ + …

This is an infinite geometric series with common ratio x.

Using the formula,

1 + x + x² + x³ + … = 1 / (1 − x)

Therefore, G(x) = 1 / (1 − x)

Example 2: Find the generating function for the sequence {0, 1, 2, 3, …}.

Solution:

The generating function is

G(x) = 0 + x + 2x² + 3x³ + …

Using the standard generating function formula,

x + 2x² + 3x³ + … = x / (1 − x)²

Therefore, G(x) = x / (1 − x)²

Example 3: Find the generating function for the sequence {1, 2, 4, 8, …}.

Solution:

The generating function is

G(x) = 1 + 2x + 4x² + 8x³ + …

This is a geometric series with common ratio 2x.

Using the formula,

1 + 2x + 4x² + … = 1 / (1 − 2x)

Therefore, G(x) = 1 / (1 − 2x)

Example 4: Find the generating function for the sequence .

Solution:

The generating function is

Using the Binomial Theorem,

Therefore,

Practice Problems

  • Problem 1: Find the generating function for the sequence {1,2,3,4,…}
  • Problem 2: Determine the generating function for the sequence {1,−1,1,−1,…}.
  • Problem 3: Find the generating function for the sequence {1,0,1,0,1,0,…}.
  • Problem 4: Derive the generating function for the sequence {1,3,5,7,…}.
  • Problem 5: Determine the generating function for the sequence {1,4,9,16,…}.
  • Problem 6: Find the generating function for the sequence {0,1,0,1,0,1,…}.
  • Problem 7: Derive the generating function for the sequence {1,1/2,1/4,1/8,…}.
  • Problem 8: Find the generating function for the sequence {1,1,0,0,1,1,0,0,…}.
  • Problem 9: Determine the generating function for the sequence {1,2,1,2,1,2,….}.
  • Problem 10: Derive the generating function for the sequence {1,3,6,10,15,…}.

Related Articles

Comment