Maths WorkshopMaths problems with full solutions
Exercise 889Combinatorics › Counting principlesOlympiadAdded 3 Nov 2026

Counting onto functions

#onto#surjections#inclusion-exclusion

Statement

Count onto functions from an nn-element set to a 22-element set.

Hint

Either the function is constant (not onto) or not. Total 2n2^n.

Show solutionHide solution

Solution

Total. 2n2^n functions.

Not onto. Two constant functions (all to 11 or all to 22).

Onto. 2n−22^n-2.

Conclusion. 2n−22^n-2 onto functions.

Check for n=2n=2. 22−2=22^2-2=2: the two non-constant functions. ✓