Mathwords logoMathwords

Stirling Numbers — Definition, Formula & Example

Stirling numbers are two families of counting numbers. The second kind, S(n,k)S(n,k), counts the ways to split nn distinct objects into kk non-empty, unlabeled groups. The first kind, c(n,k)c(n,k), counts the ways to seat nn distinct people around kk identical round tables with no table empty.

For integers n,k≥0n, k \ge 0, the Stirling number of the second kind S(n,k)S(n,k), also written {nk}\left\{ {n \atop k} \right\}, is the number of partitions of an nn-element set into exactly kk non-empty blocks. The unsigned Stirling number of the first kind c(n,k)c(n,k), also written [nk]\left[ {n \atop k} \right], is the number of permutations of an nn-element set that have exactly kk disjoint cycles. The signed version is s(n,k)=(−1)n−kc(n,k)s(n,k) = (-1)^{n-k}c(n,k). Both families satisfy S(0,0)=c(0,0)=1S(0,0) = c(0,0) = 1 and S(n,0)=c(n,0)=0S(n,0) = c(n,0) = 0 for n≥1n \ge 1. Equivalently, they are the coefficients in xn=∑kS(n,k) xk‾x^n = \sum_k S(n,k)\,x^{\underline{k}} and xn‾=∑kc(n,k) xkx^{\overline{n}} = \sum_k c(n,k)\,x^k.

Key Formula

S(n+1,k)=k S(n,k)+S(n,k−1),c(n+1,k)=n c(n,k)+c(n,k−1)S(n+1,k) = k\,S(n,k) + S(n,k-1), \qquad c(n+1,k) = n\,c(n,k) + c(n,k-1)
Where:
  • nn = Number of distinct objects already placed (the new object is number n + 1)
  • kk = Number of blocks (second kind) or cycles (first kind)
  • S(n,k)S(n,k) = Stirling number of the second kind: partitions into k unlabeled blocks
  • c(n,k)c(n,k) = Unsigned Stirling number of the first kind: permutations with k cycles

Worked Example

Problem: Five people sit at 2 identical round tables, with at least one person at each table. Only who sits next to whom, going clockwise, matters. How many seatings are possible? Compare this with the number of ways to split the same 5 people into 2 groups when seating order does not matter.
Step 1: Start from small cases. With 3 people, c(3,2)=3c(3,2) = 3 (one pair at one table and a single person at the other) and c(3,1)=2c(3,1) = 2 (two clockwise orders at one table). Apply the first-kind recurrence with n=3n = 3.
c(4,2)=3 c(3,2)+c(3,1)=3⋅3+2=11c(4,2) = 3\,c(3,2) + c(3,1) = 3 \cdot 3 + 2 = 11
Step 2: Add the fifth person. Either this person sits to the left of one of the 4 people already seated, giving 4 c(4,2)4\,c(4,2) ways, or this person sits alone while the other 4 share one table, giving c(4,1)=3!=6c(4,1) = 3! = 6 ways.
c(5,2)=4 c(4,2)+c(4,1)=4⋅11+6=50c(5,2) = 4\,c(4,2) + c(4,1) = 4 \cdot 11 + 6 = 50
Step 3: For plain groups, use the second-kind recurrence. Here the new person joins one of the k=2k = 2 existing groups or starts a new group. Use S(4,2)=7S(4,2) = 7 and S(4,1)=1S(4,1) = 1.
S(5,2)=2 S(4,2)+S(4,1)=2⋅7+1=15S(5,2) = 2\,S(4,2) + S(4,1) = 2 \cdot 7 + 1 = 15
Answer: There are c(5,2)=50c(5,2) = 50 round-table seatings but only S(5,2)=15S(5,2) = 15 ways to form the two groups. The first kind is larger because it also counts the cyclic order within each group.

Why It Matters

In discrete math and algorithm analysis, you use S(n,k)S(n,k) to rewrite powers as falling factorials, which turns sums like ∑k3\sum k^3 into easy telescoping sums. The quantity k! S(n,k)k!\,S(n,k) counts onto functions from an nn-set to a kk-set. If you sum S(n,k)S(n,k) over every kk, you get the Bell number BnB_n. So Bell numbers give only the total number of partitions, while Stirling numbers give the count for each number of blocks.

Common Mistakes

Mistake: Using the multiplier kk in the first-kind recurrence. For example, a student writes c(5,2)=2 c(4,2)+c(4,1)=2⋅11+6=28c(5,2) = 2\,c(4,2) + c(4,1) = 2 \cdot 11 + 6 = 28.
Correction: In the second kind, a new object joins one of kk blocks, so the multiplier is kk. In the first kind, a new person can sit to the left of any of the nn people already seated, so the multiplier is nn. The correct value is c(5,2)=4⋅11+6=50c(5,2) = 4 \cdot 11 + 6 = 50.

Related Terms

  • Bell Number — Sums second-kind Stirling numbers over all block counts
  • Twelvefold Way — Uses S(n,k) for distinct balls in identical boxes
  • Permutation Cycle — First-kind Stirling numbers count permutations by how many cycles they have
  • Multinomial Coefficient — Counts splits into labeled groups of fixed sizes instead
  • Combinatorics — Parent field studying these partition and cycle counts