The idea
Key formulas
Two-set inclusion-exclusion
Three-set inclusion-exclusion
Loading lessons…
Just a moment, getting everything ready. The first load can take up to a minute.
Discrete maths
Inclusion-exclusion corrects overcounting among overlapping sets, while pigeonhole arguments force repeated assignments.
To count a union, add the sizes of the sets, then correct for objects counted more than once. For two sets, subtract their intersection. For three sets, subtract each pairwise intersection but add the triple intersection back. For any finite family, alternate signs over nonempty intersections. This is the inclusion-exclusion principle.
The same principle counts functions that hit every target. To count surjections from an -element domain onto an -element codomain, begin with all functions and exclude those that miss at least one target. Derangements are permutations with no fixed points; inclusion-exclusion gives .
The pigeonhole principle says that placing more objects than boxes forces some box to contain multiple objects. In its generalized form, placing objects into boxes puts at least objects in some box. Both ideas turn overlaps or repeated assignments into exact counts or guaranteed lower bounds.