Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 31

Enumerating Labeled Structures with Exponential Generating Functions

Recommended resources

Welcome to the final lesson in our module on recurrence relations and generating functions. In our previous lessons, you've mastered how to use Ordinary Generating Functions (OGFs) to solve complex counting problems, from linear recurrences to the non-linear recurrence that defines the Catalan numbers. OGFs are the perfect tool when we are counting structures built from indistinguishable items, like counting ways to make change with coins of different denominations.

Today, we shift our focus to problems involving distinct or labeled objects. How many ways can we arrange the letters in a word? How many ways can we assign a group of distinct people to different tasks? For these questions, we need a new tool: the Exponential Generating Function (EGF). Your goal is to understand what EGFs are, how their multiplication rule elegantly handles labeled objects, and how to apply them to enumerate permutations and other labeled structures, a common theme in advanced combinatorics.

The Labeled World: Introducing Exponential Generating Functions

An Ordinary Generating Function (OGF) for a sequence is defined as . The key modification for an EGF is the inclusion of a factorial term.

The Exponential Generating Function for a sequence is defined as:

Why this change? The answer lies in the product rule. For OGFs, the product corresponds to combining two unlabeled structures. For EGFs, the product corresponds to combining two labeled structures.

To understand this critical distinction, please read the following brief introduction.

Power Series and Generating Functions (IV) – Exponential Generating Functions | Mathematics and Such

This blog post from Mathematics and Such provides a clear and concise explanation of what EGFs are and, most importantly, why they are used for labeled sets.

Read from the beginning of the post. Pay close attention to the two bullet points that contrast the combinatorial interpretation of multiplication for OGFs and EGFs. The key formula for EGFs is: a_n = \sum_{k=0}^n \binom{n}{k} b_k c_{n-k} This shows how a problem of size n is broken down by first choosing \binom{n}{k} labeled items for one part, then applying a structure of type B to them, and a structure of type C to the rest. This \binom{n}{k} factor is precisely what the n! denominators in the EGF definition account for.

The core takeaway is that the multiplication of EGFs, , automatically generates a sequence that follows the rule for partitioning labeled sets. This is the superpower of EGFs.


Application 1: Permutations of a Multiset

Let's see this in action. A classic use of EGFs is counting the number of arrangements (permutations) of a multiset, where some items are repeated but are still distinct types. For instance, how many 4-letter "words" can we form from the letters in PAPAYA?

The letters available are three Ps, two As, and one Y. We want to form a 4-letter word. We can think of this as building a structure of size 4 by picking letters from three different "bins".

The EGF for the P bin (we can choose 0, 1, 2, or 3 Ps) is:

The EGF for the A bin (we can choose 0, 1, or 2 As) is:

The EGF for the Y bin (we can choose 0 or 1 Y) is:

The EGF for the combined problem is the product . The number of ways to form a 4-letter word is , which we find by looking at the coefficient of in . In other words, .

The following video walks through this exact "PAPAYA" example and explains the mechanics of setting up the EGFs for each available letter and extracting the final count.

Exponential Generating Function | Counting Problems

This video from MathPod demonstrates the application of EGFs to permutations with identical items.

Watch the segment from the beginning of the PAPAYA example. Follow how the EGF for each letter type is constructed and how they are multiplied. The instructor then calculates the coefficient of x^4 to find the number of 4-letter arrangements. Notice the final step: the coefficient you find must be multiplied by n! (in this case, 4!) to get the final answer.


Application 2: Labeled Structures and the Exponential Formula

While the multiset permutation problem is a standard application, the true power of EGFs in advanced combinatorics comes from a principle often called the Exponential Formula. This is a framework for counting complex labeled objects by first counting their basic, "connected" components.

A prime example is counting permutations with specific cycle structures. A permutation of elements can be uniquely decomposed into disjoint cycles. The cycles are the "components."

  1. Count the components: First, we find the EGF for a single component. How many ways can we form a single cycle on labeled elements? The answer is . So, the sequence for one cycle is for , and . The EGF for a single cycle is:

  2. Combine the components: A general permutation is a set of these cycles. If we have cycles, the EGF would be (we divide by because the cycles themselves are indistinguishable). To account for any number of cycles, we sum over all possible :

This is the Exponential Formula: if is the EGF for a single component, then is the EGF for a structure made of any number of those components.

For all permutations, the EGF is . The coefficients of this EGF are , which is correct!

This framework is incredibly versatile. By modifying , we can count permutations with various restrictions. The following reading explores this idea in detail.

[Tutorial] Generating Functions in Competitive ...

This Codeforces tutorial provides a fantastic overview of using EGFs to count permutations and other labeled structures, framed in a way that is perfect for competitive programming and Olympiad-style problems.

Please read the following three sections: "Some problems involving permutations": This section introduces the core idea of using the EGF for a single cycle (C(x) = -\ln(1-x)) and the exponential formula to count permutations with a fixed number of cycles or with cycle lengths from a specific set. "Stirling Numbers of the Second Kind": This shows another application of the same principle, this time to partition a set of n labeled elements into k non-empty subsets. The "component" here is a single non-empty set. "Graph Counting": This shows how to count labeled graphs where every vertex has degree 2. Such a graph is a union of disjoint cycles, so the same logic applies. As you read, focus on the pattern: define the EGF for one component, then use powers and the exponential function to build the EGF for the full structure.


Practice Problems

It's time to apply these concepts.

  1. Word Arrangements: How many 5-letter "words" can be formed using the digits {1, 1, 2, 3, 4}? Set up the EGFs for each digit and find the coefficient that gives the answer.

  2. Derangements: A derangement is a permutation with no fixed points. This means it has no cycles of length 1.
    (a) Start with the EGF for a single cycle, . What is the new component EGF, , if cycles of length 1 are forbidden?
    (b) The EGF for derangements is . Show that this simplifies to .
    (c) By multiplying the series for and , find the coefficient of in to re-derive the famous formula for the number of derangements, .

  3. Involutions: An involution is a permutation such that is the identity. This means all cycles in its decomposition have length 1 or 2.
    (a) What is the EGF, , for a single component (a cycle of length 1 or 2)?
    (b) Using the exponential formula, write down the EGF, , for the total number of involutions on elements.
    (c) Use your result from (b) to calculate the number of involutions on 4 elements, . (You'll need to compute ).

  4. A Deeper Dive (Challenge): The video below provides a complete derivation for Lah numbers, which count partitions of into ordered subsets. It's an excellent case study of the entire generating function pipeline, from recurrence to differential equation to closed form.

Lah Numbers and an appearance of exponential generating functions

This video by Michael Penn is a masterclass in using EGFs.

Watch the first two parts of the video. First, understand how the recurrence relation for Lah numbers is built (Recurrence derivation). Then, watch carefully as this recurrence is translated into a first-order linear differential equation for the EGF (EGF and Differential Equation). In your own words, explain how the terms in the recurrence L(n+1,k) = L(n, k-1) + (n+k)L(n,k) correspond to the terms in the differential equation for the EGF L_k'(x).


Conclusion

In this lesson, you've added a powerful new instrument to your combinatorial toolkit. You learned that while Ordinary Generating Functions count structures on unlabeled sets, Exponential Generating Functions are designed for labeled sets. The key is their product rule, , which naturally models the process of splitting a labeled set. We saw how to use this for direct counting problems, like word arrangements, and for more abstract structures via the Exponential Formula, , which allows us to count objects built from smaller, independent components like cycles in a permutation.

This lesson concludes our module on generating functions. You have progressed from basic recurrence relations to the sophisticated machinery used to solve Olympiad-level counting problems. In our next module, we will begin our study of Graph Theory. Many of the concepts we've touched upon—such as permutations as cycles, or network-like problems—are most naturally described using the language of graphs. We will start by defining the fundamental terminology of vertices, edges, paths, and cycles.