Maths WorkshopMaths problems with full solutions
Exercise 1629Combinatorics › Counting principlesL1Added 3 Nov 2026

Counting surjections

#surjections#inclusion-exclusion#Stirling

Statement

Count surjective functions from an mm-element set to an nn-element set (with m≥nm\ge n).

Hint

Use inclusion-exclusion on which elements are missed.

Show solutionHide solution

Solution

Total. nmn^m functions.

Inclusion-exclusion. Subtract those missing at least one element:
∑k=0n(−1)k(nk)(n−k)m=n!⋅S(m,n),\sum_{k=0}^{n}(-1)^k\binom{n}{k}(n-k)^m=n!\cdot S(m,n),
where S(m,n)S(m,n) is the Stirling number of the second kind.

Conclusion. Number of surjections =n! S(m,n)=∑k=0n(−1)k(nk)(n−k)m=n!\,S(m,n)=\sum_{k=0}^{n}(-1)^k\binom{n}{k}(n-k)^m.

Example. m=nm=n: surjections = n!n!.