Skip to main content

Welcome to a Grasp lesson

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

Lesson 17

Stirling Numbers of the Second Kind: Set Partitions

Recommended resources

Welcome back. In our last lesson, we derived a powerful formula using the Principle of Inclusion-Exclusion (PIE) to count the number of surjective functions from a set of size to a set of size . This corresponds to distributing distinct items into distinct boxes, ensuring no box is empty.

Today, we'll explore a closely related, and equally fundamental, combinatorial object: Stirling numbers of the second kind. These numbers answer a similar question but with a crucial twist: what if the boxes are indistinguishable? This seemingly small change leads to the concept of set partitions, a cornerstone of enumerative combinatorics. Our goal is to define these numbers, learn how to compute them using both a recurrence relation and an explicit formula derived from our work with surjections, and apply them to solve partitioning problems.

What is a Set Partition?

Imagine you have a set of distinct objects, and you want to divide them into non-empty groups. The order of groups doesn't matter, and the order of elements within a group doesn't matter. This is called a partition of the set.

The number of ways to partition a set of elements into exactly non-empty subsets is given by the Stirling number of the second kind, denoted as or .

From a "balls and boxes" perspective:

  • We have distinct balls (the elements of the set).
  • We have identical boxes (the subsets are indistinguishable).
  • Each box must contain at least one ball (the subsets must be non-empty).

The following video provides an excellent introduction to this concept.

Meet the Stirling Numbers! (of the 2nd kind)

The video "Meet the Stirling Numbers! (of the 2nd kind)" from the Wrath of Math channel introduces the core idea using the intuitive 'balls and boxes' analogy.

Watch the first few minutes, from the beginning, to see how a simple problem of partitioning 3 balls into 2 boxes leads to the formal definition of S(n, k). Pay attention to the distinction between distinct balls and indistinguishable boxes.

For example, let's find , the number of ways to partition the set into 2 non-empty subsets.
The possible partitions are:

So, . Note that the partition is identical to because the "boxes" (the subsets) are indistinguishable.


Computing Stirling Numbers: The Recurrence Relation

Calculating by listing all partitions becomes impractical very quickly. A more efficient method is to use a recurrence relation, similar to the one that generates Pascal's triangle for binomial coefficients.

To find , we can single out one specific element from our set of elements, let's call it element . When we partition the elements into subsets, there are two possibilities for element :

  1. Element is in a subset by itself. If is one of the subsets, then the remaining elements must be partitioned into the remaining subsets. The number of ways to do this is .
  2. Element is in a subset with other elements. If is not alone, we can first partition the other elements into non-empty subsets. There are ways to do this. Then, we must place element into one of these existing subsets. Since the subsets are formed, they are now distinguishable by their contents, giving us choices for where to place element . This gives ways.

By the sum rule, we get the recurrence relation:

The boundary conditions are , , and for .

The following resource provides a formal combinatorial argument for this recurrence and other basic identities.

[PDF] Stirling Numbers of the Second Kind - MIT Mathematics

This document provides clear proofs for the fundamental properties of Stirling numbers.

Read the section "Stirling Number Identities". Focus on the combinatorial proofs for the special cases S(n, 1), S(n, n-1), and the proof for the recurrence relation, which uses the "kids and committees" analogy.

This recurrence allows us to build a triangle for Stirling numbers, much like Pascal's triangle.

A table of Stirling numbers of the second kind, \(S(n,k)\). Each entry is calculated using the recurrence relation from the two entries above it: the one to the left, and the one directly above multiplied by its column index \(k\).

Let's use the recurrence to verify the value of from the table.

From the table, and .
So, , which matches the table.


The Explicit Formula via Surjective Functions

We can also find an explicit formula for by connecting it to our previous lesson on surjective functions.

  • Surjective functions: Counting ways to put distinct balls into distinct boxes (no empty boxes).
  • Stirling numbers : Counting ways to put distinct balls into indistinguishable boxes (no empty boxes).

The only difference is whether the boxes are distinct or not. We can count the number of surjections in two steps:

  1. First, partition the balls into non-empty piles. This is exactly what counts.
  2. Then, assign the distinct labels of the boxes to these piles. There are ways to do this.

This gives us a fundamental relationship:

In the last lesson, we used PIE to find the formula for the number of surjections:

By rearranging the relationship above, we get our explicit formula for the Stirling numbers of the second kind:

The following "active learning" worksheet guides you through this derivation, forcing you to reconstruct the PIE argument. This is excellent practice for your goal of mastering proofs.

[PDF] Active learning exercise on Stirling numbers of the second kind

This worksheet guides you to derive the explicit formula for S(n,k) by first considering partitions into labeled blocks.

Start reading from the heading that introduces a "closely related number S-hat(n, k)" at the bottom of page 2. This \hat{S}(n,k) is precisely the number of surjective functions. Now, work through the questions: Exercise 6: This question asks you to formalize the relationship we just discussed. Exercise 7: These questions rebuild the PIE argument. Answer parts (a) through (d) by thinking about the total number of functions (k^n) and the number of functions that miss 1, 2, or more specified codomain elements. Exercise 8: This exercise puts it all together. Use your answers from Exercise 7 and the logic of PIE to prove formula (1), and then use your result from Exercise 6 to get the final formula for S(n, k).


An Extension: Bell Numbers

A natural question arises: how many ways are there to partition a set of elements if we don't specify the number of subsets? This total number of partitions is the -th Bell Number, denoted .

Since we can partition a set of elements into 1 subset, or 2 subsets, ..., or subsets, the Bell number is simply the sum of the Stirling numbers over all possible values of :

If you look back at the image Stirling Numbers of the Second Kind, the Bell numbers are conveniently listed as the row sums. For example, .


Practice Problems

Now, let's apply these concepts. As per your preference, here are a few problems to solidify your understanding.

  1. Using the Recurrence: Calculate using the recurrence relation and the values from the provided table.
  2. Using the Formula: Calculate using the explicit PIE formula. Verify that your answer matches the value in the table ().
  3. Word Problem: In how many ways can 8 distinct toys be distributed among 3 identical boxes if no box is to be empty?
  4. Equivalence Relations: An equivalence relation on a set is a way of partitioning it into non-empty subsets called equivalence classes. How many distinct equivalence relations can be defined on the set ?

Conclusion

In this lesson, we have formally defined Stirling numbers of the second kind, , as the number of ways to partition an -element set into non-empty subsets. This is a fundamental concept in combinatorics that models any problem involving grouping distinct items into identical containers.

Key Takeaways:

  • Definition: counts the partitions of an -set into non-empty blocks.
  • Recurrence Relation: . This provides a simple way to compute values recursively.
  • Connection to Surjections: The number of surjections from an -set to a -set is .
  • Explicit Formula (via PIE): . This formula directly links set partitions to the Principle of Inclusion-Exclusion.
  • Bell Numbers: The total number of partitions of an -set, , is the sum of for .

This lesson concludes our module on the Principle of Inclusion-Exclusion. We have seen how this single principle can be used to solve seemingly disparate problems like counting derangements, surjective functions, and now set partitions.

In our next lesson, we will begin a new module and introduce a different, yet equally elegant, proof technique: double counting. We will see how counting the size of a set in two different ways can lead to surprisingly powerful combinatorial identities.