Imagine you want to count the integers from 1 to 1000 that are divisible by 2, by 3, or by both. You can't just add the two groups — you'd count multiples of 6 twice. So you subtract them back. That one fix is the entire soul of inclusion-exclusion.
The principle generalizes immediately: to count the integers that fall in at least one of several sets, alternately add all individual set sizes, subtract all pairwise intersections, add all triple intersections, and so on. Every object gets counted exactly once no matter how many sets it belongs to.
Written as a formula for sets , , …, :
The alternating signs come from the binomial theorem: an element belonging to exactly of the sets is counted times overall. This is a classical result of combinatorics; it was known to Sylvester (1879) and Poincaré in various forms.
The principle is solved mathematics — the formula is exact and its proof is elementary — but its role in algorithm design continues to surprise: it converts exponential brute-force searches into structured alternating sums that can be evaluated in polynomial or quasi-polynomial time for problems that look much harder.
Comments
Loading comments...