Contents / Combinatorics / Counting Principles
Chapter 2
Counting Principles
The rules every count rests on: bijections, the sum and product rules, pigeonhole, inclusion–exclusion and double counting.
Introduction
The rules every count rests on: bijections, the sum and product rules, pigeonhole, inclusion–exclusion and double counting.
2.1Sets, Bijections and the Two Basic Rules
Before anything can be counted, "the number of elements" has to mean something. The definition is the one recorded in Basic Counting, restated here in the vocabulary this chapter uses throughout: a set has elements when it can be labelled through without repetition and without omission, and such a labelling is called a listing.
Definition 2.1 (Cardinality of a finite set). A set is finite of cardinality , written , if there is a bijection , where and . Such an is a listing of : it writes as with all entries distinct.
Note. That the integer is unique — that no set admits both a listing of length and a listing of length — is the pigeonhole principle in disguise, and is proved as a corollary at the end of this section. Until then, read " " as "some listing of length exists".
Everything in this chapter is ultimately an argument about listings. The three rules that manipulate them were stated and proved in Basic Counting, the preceding chapter, and are used here without reproof. In the form needed below: the bijection principle says that if there is a bijection then , because composing with a listing of is a listing of ; the sum rule says that pairwise disjoint sets satisfy ; and the product rule says that . Every argument in this chapter rests on these three and on nothing else.
The bijection principle looks like bookkeeping at this stage. Its power appears later: to prove two complicated families have the same size one need not compute either size. The section Bijections and counting in two ways develops the idea properly.
Pitfall. Disjointness is not decoration — it is the only hypothesis the proof of the sum rule uses, and dropping it makes the conclusion false. With and the sum rule would claim , while has three elements. Repairing exactly this failure is what inclusion–exclusion is for.
The product rule is usually applied in a slightly stronger form, and it is worth being precise about why the stronger form is legitimate.
Proposition 2.2 (Sequential choice rule). Suppose each object of a set is built by a sequence of choices, where the number of options at step is a constant independent of how the earlier choices were made, and distinct choice sequences build distinct objects. Then .
Proof. Induct on . For the claim is the definition of . For , group the objects of by their first choice. Distinct sequences give distinct objects, so no object arises from two different first choices and the groups are pairwise disjoint; their union is . Each group consists of the objects extending one fixed first choice, built by further choices with options, so by induction each group has elements. There are groups, so the sum rule gives .∎
Pitfall. "Independent of how the earlier choices were made" refers to the number of options, not to which options they are. When you seat people in chairs, the second person's available chairs depend entirely on where the first sat — but there are always exactly of them, so the rule applies and gives . The rule genuinely fails when the count itself varies with the history, and then the product must be replaced by a sum over cases.
Example 2.3 (Both rules in one problem). How many strings of length over the alphabet either consist entirely of vowels ( and ) or have four distinct letters?
Solution. Let be the set of all-vowel strings and the set of strings with four distinct letters.
Each of the four positions of a string in is filled independently from the vowels, so the product rule gives .
A string in is built by choosing its first letter ( ways), then a different second letter ( ways), then a third (), then a fourth (). The counts do not depend on which letters were used, so the sequential choice rule gives .
Are the two sets disjoint? An element of would be a string of four distinct letters all drawn from a two-letter alphabet, which the pigeonhole principle below forbids outright. So , the sum rule applies, and the answer is .□
Intuition. The two rules are "or" and "and". If an object is an -thing or a -thing, and never both, add. If an object is an -thing and a -thing chosen separately, multiply. Nearly every elementary counting error is a misdiagnosis of which of those two words fits — or an "or" whose cases secretly overlap.
With the two rules in place we can state the principle that gives this chapter half its name. It says a set cannot be squeezed into a smaller one without a collision.
Theorem 2.4 (Pigeonhole principle). Let and be finite sets with . Then no function is injective: there exist distinct with .
Equivalently: if objects are placed into boxes and , some box contains at least two objects.
Proof. Suppose for contradiction that is injective. For write . The sets are pairwise disjoint, since each has exactly one image, and their union is ; so the sum rule gives
Injectivity says for every , so the right-hand side is a sum of terms each at most , hence at most . Thus , contradicting .∎
Notice what the proof used: only the sum rule and the bound . Everything in the next section comes from replacing that by a larger number.
Corollary 2.5 (Cardinality is well defined). No finite set admits listings of two different lengths: if and are both bijections, then .
Proof. The composite is a bijection, hence injective, so the pigeonhole principle forbids . Symmetrically is injective, so is forbidden too. Hence .∎
Corollary 2.6 (Injections, surjections and equal size). Let and be finite sets.
- If there is an injection then .
- If there is a surjection then .
- If , a function is injective if and only if it is surjective.
Proof. Part 1 is the contrapositive of the pigeonhole principle. For part 2, let be surjective and pick for each some with . Then is injective, because gives ; now apply part 1.
For part 3, decompose into the fibres , so , a sum of terms whose total is . If is injective every term is at most ; a sum of terms each at most that equals must have every term equal to , so every fibre is non-empty and is surjective. If is surjective every term is at least , and the same accounting forces every term to equal , so no fibre has two elements and is injective.∎
Remark. Part 3 fails spectacularly for infinite sets: is an injection that is not surjective. That failure is not a defect but a definition — Dedekind takes it as the definition of infinite. Every pigeonhole argument in this chapter therefore depends on finiteness, and the hypothesis is never harmless.
Intuition. Thirteen socks, twelve drawers: however carefully you spread them out, some drawer ends up with two. You do not learn which drawer, and no cleverness in the spreading can help. The principle states what arithmetic forbids, not what strategy achieves.
Example 2.7 (The birthday guarantee, and its threshold). Show that among any people two share a birthday (allowing February, so possible dates), and that is the smallest number for which this is guaranteed.
Solution. Let be the set of people, , let be the set of dates, and let send a person to their birthday. Since , the pigeonhole principle says is not injective, so two distinct people share a date.
For minimality, exhibit people with no repeat: give the -th person the -th date, which is possible precisely because dates exist. So people can avoid a collision and is exactly the threshold.
This second half is worth naming, because every sharp pigeonhole bound needs it. The principle supplies a sufficient number; showing that number is also necessary requires constructing a collision-free configuration one size smaller.□
Example 2.8 (A counting argument disguised as a pigeonhole argument). Show that in any group of people, two people have the same number of acquaintances within the group. (Acquaintance is mutual, and nobody is their own acquaintance.)
Solution. Each person has an acquaintance count in , which is possible values for people — not yet a contradiction, so the naive pigeonhole fails and the boxes must be chosen more carefully.
The point is that the values and cannot both occur: if someone knows everyone else, then nobody knows nobody, and conversely. So the actual value set is contained either in or in , and in either case has at most elements. Now people map into at most boxes, and the pigeonhole principle forces two people into the same box.
This is the pattern to internalise: the hard part of a pigeonhole proof is almost never the principle. It is designing the boxes so that the collision means what you want.□
2.2The Generalised Pigeonhole Principle
The basic principle promises only "at least two". Often more is needed: what forces "at least three", or "at least "? The proof above answers this immediately, because it never used the number for any reason other than that injectivity supplied it.
Theorem 2.9 (Generalised pigeonhole principle). Let with , finite and . If for a positive integer , then some fibre has at least elements: there is with .
In box language: objects in boxes force some box to contain at least objects.
Proof. Suppose every fibre had at most elements. The fibres are disjoint with union , so by the sum rule
contradicting .∎
Proposition 2.10 (The bound is sharp). For all positive integers and there is a distribution of objects into boxes in which no box holds objects. Hence is the least number of objects that forces a box of size .
Proof. Put exactly objects in each of the boxes. The total is and no box reaches . Together with the theorem, this shows the threshold is exactly .∎
The same fact is often more convenient in a form that takes the number of objects as given and reports the guaranteed load of the fullest box.
Corollary 2.11 (Ceiling form). If objects are placed into boxes, some box contains at least objects, and some box contains at most objects. Here is the least integer and the greatest integer .
Proof. For the first claim, suppose every box held at most objects. Since , the sum rule would give
which is absurd. The second claim is the same argument with the inequalities reversed: if every box held at least objects, the total would exceed .∎
Remark. The ceiling form is exactly the statement that the maximum of a list is at least its average, and the minimum at most its average — with the extra information that box loads are integers, which is where the ceiling and floor come from. Stated that way it generalises far beyond boxes: in any finite list of real numbers, some entry is at least the mean. That averaging principle is the form the argument usually takes in analysis and graph theory.
Pitfall. The ceiling form is a statement about the fullest box, not about every box and not about a box you get to name. If letters are sorted into sacks, some sack holds at least letters — but nine sacks may be empty, and the sack you are interested in may be one of them.
Intuition. To force three socks into one of twelve drawers, first imagine an adversary trying to prevent it. The best they can do is two per drawer, which uses socks. The th sock has nowhere safe to go. Every generalised-pigeonhole bound is that adversary calculation: fill each box as far as the target allows, count, and add one.
Example 2.13 (Candies and children). One hundred identical candies are given to children. What is the largest number such that, in every possible distribution, some child receives at least candies?
Solution. By the ceiling form with and : since , we get , so in every distribution some child gets at least .
No larger claim is possible. The distribution totals and has no child above , so "some child gets at least " is false for that distribution. Hence exactly.
Both halves matter: the ceiling form gives the guarantee, and an explicit distribution shows the guarantee cannot be improved.□
Example 2.14 (Forcing a large monochromatic set). A bag contains balls in colours. How many balls must be drawn to guarantee of the same colour? What if the bag contains only red balls?
Solution. Colours are the boxes, , and the target is . The generalised pigeonhole principle gives the threshold , and the sharpness proposition confirms is not enough: six of each colour is a -ball draw with no colour reaching seven.
If red is limited to balls, the adversary's best blocking configuration is no longer uniform: red can contribute at most , while the other three colours contribute each. That gives balls with no colour reaching , so draws now suffice and do not. The threshold is .
The moral is that the clean formula is the answer to the unconstrained problem. When supplies are bounded, go back to the underlying argument — maximise the blocking configuration, then add one — rather than to the formula.□
Example 2.15 (A pigeonhole bound with a non-obvious box design). Show that any sequence of distinct real numbers contains a monotone subsequence of length — increasing or decreasing.
Solution. This is the Erdős–Szekeres theorem, and it is proved in full in the next section. The point to see here is the shape of the argument: to each term attach the pair , where is the length of the longest increasing subsequence ending at and the length of the longest decreasing one ending at . If no monotone subsequence of length exists, each coordinate lies in , so the pairs live in a set of boxes while there are terms.
The generalised principle is not even needed — the basic one suffices once the boxes are right. Designing is the entire content of the proof; see the next section for why two terms in the same box are impossible.□
2.3Existence Proofs: Ramsey, Erdős–Szekeres and Dirichlet
The pigeonhole principle is a non-constructive tool: it certifies that a collision exists without saying where. Three classical theorems show how much can be extracted from that, and all three are proved here in full.
Theorem 2.16 (Divisibility by design of boxes). Let .
- Among any integers, two have a difference divisible by .
- Among any integers chosen from , one divides another.
Proof. For part 1, map each integer to its residue class modulo . There are residues and integers, so by the pigeonhole principle two integers share a residue, and then .
For part 2, write each chosen integer uniquely as with odd — this is possible and unique because factoring out the largest power of leaves an odd number. Each odd part lies in , a set of exactly values, while we have integers. The pigeonhole principle gives two chosen integers and with the same odd part; since we have , and whichever exponent is smaller yields a divisor of the other.∎
Remark. Part 2 is sharp: the integers lie in and none divides another, because the ratio of any two of them is strictly between and . So is genuinely needed.
Example 2.17 (Consecutive terms summing to a multiple). Let be any integers. Show that some block of consecutive terms is divisible by .
Solution. Form the partial sums and for . That is integers, so by part 1 of the theorem above two of them, say and with , are congruent modulo . Then
The block is non-empty because . Note how the boxes were designed: the sums, not the terms. Applying the principle directly to would have given nothing, since objects in boxes force no collision.□
Theorem 2.18 (Ramsey's theorem for triangles). Colour each of the edges of the complete graph red or blue, arbitrarily. Then there is a monochromatic triangle: three vertices whose three connecting edges all have the same colour.
Proof. Fix a vertex . It meets edges, each coloured red or blue, so by the generalised pigeonhole principle with boxes and — note — at least three of them share a colour. Say is joined to , , all in red (the blue case is identical with the colours exchanged).
Now consider the three edges , , . If any one of them is red, say , then , , form a red triangle. If none is red, then all three are blue and , , form a blue triangle. Either way a monochromatic triangle exists.∎
Proposition 2.19 (Six is optimal). There is a red/blue colouring of the edges of with no monochromatic triangle. Hence the Ramsey number equals .
Proof. Place the five vertices on a circle. Colour the five edges of the outer pentagon red and the five diagonals blue. The red edges form a -cycle, and a cycle of length contains no triangle, since a triangle would require three mutually adjacent vertices and in a -cycle no two edges sharing no vertex can be completed. Concretely, with vertices and red edges joining to , a red triangle would need three vertices pairwise at circular distance , which is impossible. The blue edges join to , and these also form a -cycle (in the order ), so the same argument applies. No monochromatic triangle exists.∎
Intuition. In any party of six people, there are three who all know each other or three who are all mutual strangers. The proof is nothing but "look at one person: among their five relationships, three are of the same kind" — and then a single case check. The result is genuinely surprising, and the proof is four lines; that gap is what makes pigeonhole arguments memorable.
Theorem 2.20 (Erdős–Szekeres). Let . Every sequence of distinct real numbers contains an increasing subsequence of length or a decreasing subsequence of length .
Proof. Let the sequence be . For each index let be the length of the longest increasing subsequence ending at , and the length of the longest decreasing subsequence ending at . Both are at least , since the single term qualifies.
Suppose, for contradiction, that there is no increasing subsequence of length and no decreasing one of length . Then and for every , so the map sends indices into the set , which has elements by the product rule. By the pigeonhole principle there are indices with .
Now compare and ; they are distinct. If , append to a longest increasing subsequence ending at to get an increasing subsequence of length ending at , so , contradicting . If , the same move with decreasing subsequences gives , again a contradiction.∎
Proposition 2.21 (Erdős–Szekeres is sharp). There is a sequence of distinct reals with no increasing subsequence of length and no decreasing subsequence of length .
Proof. Take blocks, each an increasing run of numbers, with every number in a block larger than every number in the following block. For , this is . An increasing subsequence must stay inside a single block, because moving to a later block strictly decreases the value, so it has length at most . A decreasing subsequence uses at most one term from each block, since within a block the values increase, so it has length at most .∎
Remark. Erdős–Szekeres has a well-known geometric consequence, which is how the two authors came to it: among any points in the plane with distinct -coordinates, some or of them form a "staircase" — a set of points whose -coordinates rise or fall consistently as the -coordinates increase. Order the points by -coordinate and apply the theorem to the sequence of -coordinates.
The last classical application moves from finite boxes to intervals, and is the reason the principle is called the Schubfachprinzip or Dirichlet box principle in much of the literature.
Theorem 2.23 (Dirichlet's approximation theorem). Let be a real number and a positive integer. Then there are integers and with and
Proof. Write for the fractional part. Consider the numbers , all lying in . Partition into the half-open boxes
which are disjoint and cover . With numbers and boxes, the pigeonhole principle gives indices with and in the same box, hence
Set , so , and . Then , so , and dividing by gives . Finally gives .∎
Remark. The theorem is the gateway to continued fractions and to the theory of irrationality measures: it says every real number has infinitely many rational approximations of quality when is irrational — take and note that the resulting cannot stabilise, since for each fixed fraction while the bound tends to . Hurwitz later sharpened to , and that constant cannot be improved, as the golden ratio shows. Those refinements are beyond this chapter; we state them to mark where the elementary argument stops.
Pitfall. A pigeonhole proof tells you a collision exists and nothing else. It does not locate the collision, does not tell you how many there are, and gives no algorithm better than search. When a problem asks which pair collides, the principle is the wrong tool — or at best the first step.
The pigeonhole principle in all its forms rests on one inequality: a sum of fibre sizes equals , so they cannot all be small. The work in any application is choosing the map — residues, odd parts, partial sums, colour of an edge, the pair , an interval of . Choose the boxes well and the theorem does the rest.
2.4Inclusion–Exclusion: Two Sets
The sum rule requires disjointness. When the pieces overlap, adding their sizes counts the shared elements more than once, and the correction is the subject of the rest of this chapter's middle. We begin with two sets, where everything can be seen at once.
Theorem 2.24 (Inclusion–exclusion for two sets). For any finite sets and ,
Proof. Write . The three sets , and are pairwise disjoint and their union is : every element of the union lies in only, in only, or in both, and these cases exclude one another. So the sum rule gives
Also is the disjoint union of and , so , and likewise . Substituting into ,
Two corollaries are used constantly and deserve names of their own.
Corollary 2.25 (Subtraction rule). If are finite sets, then . In particular, for a universe and , the complement satisfies .
Proof. is the disjoint union of and , so the sum rule gives ; rearrange.∎
Corollary 2.26 (Union bound). For any finite sets, , with equality if and only if and are disjoint.
Proof. Subtract: , and this is zero exactly when .∎
Intuition. Count the cat lovers, count the dog lovers, and the people who love both have been counted twice — once in each list. Subtract them once and everybody is counted exactly once. The formula is nothing more than that sentence, and the proof above is that sentence made checkable by splitting the crowd into three groups that cannot overlap.
Example 2.28 (Sports in a class). In a class of students, play soccer, play basketball and play both. How many play at least one sport? How many play neither?
Solution. Let and be the two sets, so , , . By the two-set formula,
The students playing neither sport form the complement of in the class, so by the subtraction rule there are of them.
Check against the disjoint decomposition of the proof: soccer only , basketball only , both , neither ; and .□
Example 2.29 (Recovering an intersection). Of surveyed households, subscribe to streaming service , to service , and every household subscribes to at least one. How many subscribe to both?
Solution. "Every household subscribes to at least one" says . The two-set formula rearranges to
The formula is an equation in four quantities; any three determine the fourth. That is how inclusion–exclusion is used at least as often as in the "find the union" direction.□
Example 2.30 (Counting the complement instead). How many integers in are divisible by neither nor ?
Solution. Let be the multiples of in and the multiples of . The number of multiples of in is , because the multiples are . So and .
An integer divisible by both and is exactly one divisible by — not by , which is the trap here — so . Hence , and the count of integers divisible by neither is .□
Pitfall. The intersection of "multiples of " and "multiples of " is the multiples of , which equals only when and are coprime. Using for and would give and a final answer of , which is wrong.
2.5Inclusion–Exclusion in General
The two-set formula extends to any number of sets, with signs that alternate. We state the three-set case first because it is the one worth memorising, then prove the general theorem twice — once by induction, once by an argument that explains why the binomial coefficients cancel.
Proposition 2.31 (Three sets). For finite sets , , ,
Proof. Apply the two-set formula to :
Expand . For the last term, distributivity gives , and the two-set formula applies again:
using . Substituting and collecting terms gives the stated identity.∎
Theorem 2.32 (Inclusion–exclusion principle). Let be finite sets. For a non-empty index set write . Then
That is: add the sizes of the sets, subtract the sizes of all pairwise intersections, add back all triple intersections, and so on, with the -fold intersections carrying sign .
Proof. We count each element's contribution to both sides. Fix and let be the number of indices with ; say lies in exactly the sets indexed by , .
On the left, contributes . On the right, is counted by the term for precisely when , that is when . The number of -element subsets is , so the total contribution of to the right-hand side is
where the binomial theorem was applied to , valid because .
An element in none of the sets contributes to both sides, since it lies in no . So every element contributes equally to the two sides, and the sums over all elements agree.∎
Remark. The computation is the whole mechanism, and it has a purely combinatorial reading: a non-empty set has as many even-sized subsets as odd-sized ones. We prove that by an explicit bijection in the section Classic bijections and double counting, which makes the proof above bijective rather than algebraic.
An alternative proof by induction is also worth seeing, because it is the version that generalises to measures and probabilities, where "count each element" is unavailable.
Proposition 2.33 (Inclusion–exclusion by induction). The inclusion–exclusion principle follows from the two-set case by induction on .
Proof. The case is trivial and is the two-set theorem. Assume the formula for sets and write . The two-set formula gives
Expand by the inductive hypothesis: it contributes over non-empty . For the last term, , so the inductive hypothesis applied to the sets gives
Subtracting this term flips each sign, turning into , which is exactly the sign the general formula assigns to the index set . Together with the isolated term , every non-empty subset of appears exactly once with the correct sign.∎
The complementary form is often more useful than the union form, because in applications one usually wants the objects avoiding all of a list of bad properties.
Corollary 2.34 (Complementary form). Let be a finite universe and . Then the number of elements of lying in none of the is
with the convention , so the term is .
Proof. By the subtraction rule the left side is . Substituting the inclusion–exclusion principle and noting gives the sum over non-empty ; the term supplies .∎
Truncating the alternating sum does not merely approximate — it brackets the answer, which is frequently all one needs.
Theorem 2.35 (Bonferroni inequalities). With the notation above, let for . Then for every odd ,
and for every even the inequality is reversed. In particular and .
Proof. Repeat the element-counting proof, but stop the inner sum at . An element in exactly of the sets contributes to the truncated sum, and to the union. If the contribution is exactly , as computed before. If , use the identity , proved by induction on from Pascal's rule . It gives
so when is odd and when is even. Summing over all elements of the union gives the stated inequalities.∎
Intuition. The alternating sum overshoots and undershoots by turns, like the partial sums of an alternating series: after adding the singles you have overcounted, after subtracting the pairs you have undercounted, and each further term brings you closer. Bonferroni's inequalities say that this is not a heuristic but a theorem, which is why (the union bound) and are legitimate bounds even when the later terms are hopeless to compute.
Example 2.36 (Three sets, from the formula and from the pieces). Suppose , , , , , and . Find , and verify by decomposing into disjoint regions.
Solution. By the three-set formula,
To verify, compute the seven disjoint regions. The triple region has elements. The " and but not " region has ; similarly only has and only has . Then only is , only is , and only is . Total: , as claimed.□
Pitfall. The data in such a problem must be consistent: the seven region counts computed above must all be non-negative. If a problem states and , no such sets exist, and the formula will happily return a meaningless number. Always sanity-check by reconstructing the disjoint regions.
Example 2.37 (Four sets). At a conference, delegates attended at least one of four workshops . Each workshop had attendees, each of the six pairs shared attendees, each of the four triples shared , and delegate attended all four. Are these numbers consistent?
Solution. By the inclusion–exclusion principle with ,
This contradicts the stated , so the data are inconsistent: no such configuration exists. Note that the union bound and the Bonferroni bound were both satisfied, so neither inequality alone would have caught the error; only the full alternating sum does.□
2.6Applications of Inclusion–Exclusion
Three applications show the principle doing real work: sieving the integers, counting derangements, and counting surjections. Each follows the same template — choose a universe, choose the "bad" properties, and apply the complementary form.
Theorem 2.38 (Sieve for multiples). Let be pairwise coprime positive integers. The number of integers in divisible by none of them is
with the empty product equal to .
Proof. Take and let be the multiples of in . An integer is divisible by every with if and only if it is divisible by , which equals because the are pairwise coprime. The multiples of in are , so . Now apply the complementary form of inclusion–exclusion.∎
Corollary 2.39 (Euler's totient formula). If has distinct prime factors , then the number of integers in coprime to is
Proof. Apply the sieve with and the primes , which are pairwise coprime. An integer in is coprime to exactly when it is divisible by none of the . Since each divides , the floors are exact: . Hence
the last step being the expansion of the product: multiplying out produces exactly one term for each subset , and here .∎
Example 2.40 (Sieving to one hundred). How many integers in are divisible by , or ?
Solution. With , , the multiples of , , : , , ; , , ; and . So
Check by complement. The integers divisible by none of number . Within each block of consecutive integers there are such integers, by the totient formula applied to . Three blocks cover and give ; the tail contributes and , for in total.□
Definition 2.41 (Derangement). A derangement of is a permutation of with no fixed point: for every . The number of derangements of is written .
Theorem 2.42 (Derangement formula). For ,
and consequently is the nearest integer to for .
Proof. Let be the set of all permutations of , and for let be the set of permutations fixing . A derangement is a permutation in none of the , so the complementary form applies.
For with , the set consists of the permutations fixing every element of ; such a permutation is an arbitrary permutation of the remaining points, so . There are index sets of size , hence
For the final claim, is the -th partial sum of the alternating series for , whose terms decrease in absolute value, so the error is at most the first omitted term . Thus for , and the case (, ) is checked directly.∎
Example 2.43 (The hat-check problem). Five guests leave their hats at a party and each collects a hat at random on leaving. In how many of the possible assignments does nobody get their own hat?
Solution. This asks for . By the formula,
So of the assignments are derangements, a proportion of , strikingly close to . The convergence is fast: already at the proportion is right to three decimal places, which is the analytic content of the error bound in the proof.□
Theorem 2.44 (Counting surjections). The number of surjective functions from an -set onto a -set is
Proof. Let be the set of all functions , so by the product rule ( independent choices from values). For let be the set of functions that miss , that is, whose image avoids . A function is surjective exactly when it lies in no .
For with , the functions in are exactly the functions , and there are of them. Since there are such , the complementary form gives the stated sum.∎
Remark. Dividing by — which is legitimate because relabelling the target values permutes the surjections freely — gives the Stirling number of the second kind , the number of ways to partition an -set into non-empty unlabelled blocks. Set partitions are the subject of their own chapter; here we note only that inclusion–exclusion is where their formula comes from.
Example 2.45 (Every prize awarded). In how many ways can distinct prizes be distributed to people so that nobody goes empty-handed?
Solution. This is :
Check the magnitude: distributions in total, and , so about three quarters of distributions use all three people — plausible, since only distributions concentrated on one or two people are excluded.□
Pitfall. In the surjection count, the term contributes , which is for but for . The convention is the right one here, and it makes the formula give the correct value (the empty function is onto the empty set) and for .
2.7Bijections and Counting in Two Ways
We now return to the bijection principle and develop the two techniques it powers. The first is the bijective proof: to show , exhibit a bijection. The second is double counting: to prove an identity, count one set in two ways.
Definition 2.46 (Bijection). A map is injective if implies , surjective if every equals for some , and bijective if both. Equivalently, is bijective if and only if it has a two-sided inverse with and for all .
Proposition 2.47 (Inverses certify bijectivity). If and satisfy and , then is a bijection.
Proof. If then applying gives , so is injective. Given , the element satisfies , so is surjective.∎
Method 2.48 (How to write a bijective proof). To prove :
- Describe the map. Give an explicit rule taking each to an object .
- Check the target. Verify — that the output really has the defining property of . This step is skipped more often than any other, and it is where most flawed bijections fail.
- Produce the inverse. Describe and check and . By the proposition above this settles injectivity and surjectivity at once.
- Conclude by the bijection principle.
An involution — a map with — is its own inverse, so step 3 is free whenever the map can be arranged to be one.
Intuition. An algebraic proof of computes two numbers and observes they agree. A bijective proof never computes anything: it pairs each object of with an object of so that nothing is left over on either side. That is why bijective proofs feel explanatory — they answer "why are these equal?" with "because they are the same objects, differently described".
The archetype of the recipe is the indicator-string bijection: a subset is matched with the string that has exactly when , its inverse reads the set of positions carrying a , and the bijection principle then gives subsets from the strings. That argument is carried out in full in Basic Counting; it is worth rereading there as an instance of the four steps above rather than as a fact about subsets.
We now formalise the second technique. It is the sum rule applied twice to the same set, and although it is almost trivial to state, naming it changes how one reads identities.
Theorem 2.49 (Double counting). Let be a finite set and let and be two decompositions of into pairwise disjoint parts. Then
Proof. Both equalities are the sum rule applied to the respective decomposition; the middle quantity is the same number in each case, since it is the size of the same set.∎
Corollary 2.50 (Counting a table in two directions). Let be any relation between finite sets, and for , write and . Then
Proof. The sets , one for each , are pairwise disjoint with union , and via the bijection . The sets for give a second such decomposition with . Apply the double counting theorem.∎
Intuition. Write the relation as a grid of ticks: rows indexed by , columns by , a tick in cell when . Count the ticks row by row and you get ; count them column by column and you get . The ticks did not move, so the totals agree. Every double-counting proof is that picture with a well-chosen grid.
Theorem 2.51 (Handshake lemma). In any finite graph , the degrees sum to twice the number of edges:
Consequently the number of vertices of odd degree is even.
Proof. Apply the table corollary to the incidence relation . Row sums: for fixed , the number of incident edges is , so . Column sums: each edge has exactly two endpoints, so for every and .
For the consequence, split the sum by parity: . The total is even and the first part is even, so the second is even; being a sum of odd numbers, it can be even only if it has an even number of terms.∎
Example 2.52 (There is always a repeat handshake). At a party some pairs shake hands. Show that the number of people who shook hands an odd number of times is even.
Solution. Model the party as a graph: people are vertices, handshakes are edges, and the number of handshakes a person made is their degree. The handshake lemma says the number of odd-degree vertices is even, which is exactly the claim.
Note what was gained: the statement concerns the parity of a count over a structure that may be arbitrarily complicated, and the proof never examines the structure at all. It only counts incidences twice.□
Theorem 2.53 (Binomial identities by double counting). For integers :
- .
- for , and hence .
- (Vandermonde) .
Proof.
- Count the subsets of in two ways. All at once, there are of them. Alternatively, partition them by size: the subsets of size number , and every subset has exactly one size, so the parts are disjoint and cover. Double counting gives the identity.
- Count pairs with , , and — "a committee of with a designated chair". Choosing the committee first gives committees and then choices of chair, so the count is . Choosing the chair first gives choices, and then the other members are any -subset of the remaining people, so the count is . For the consequence, sum over and use part 1 applied to : .
- Count the -element subsets of a set of elements that has been split into a block of size and a block of size . Directly there are . Alternatively classify by , which takes one value per subset, so the classes are disjoint and cover; a subset with is determined by choosing elements of and of , which by the product rule can be done in ways. Summing over gives the identity.
Remark. Identity 2 is worth rereading as a slogan: choose the special element first. Whenever a formula has a stray factor of or in front of a binomial coefficient, there is usually a distinguished element being chosen, and pinning down what it is converts the algebra into a sentence.
Example 2.54 (The hockey-stick identity). Prove that for .
Solution. Count the -element subsets of in two ways.
Directly there are of them.
Alternatively, classify each subset by its largest element . Since , every subset has a well-defined largest element, and the classes are disjoint and cover. If the largest element is , the remaining elements form an arbitrary -subset of , which can be chosen in ways. As ranges over , writing gives
The "classify by the largest (or smallest) element" move is the workhorse of such proofs; once you have it, hockey-stick is not a formula to memorise but a sentence to recall.□
2.8Classic Bijections and Double Counting
This section collects the bijections every combinatorialist knows, each stated as a theorem and proved by an explicit map with an explicit inverse.
The pattern is already familiar from one case: , proved in Basic Counting by complementation , a map from the -subsets of to the -subsets that is its own inverse and hence a bijection. Every proof below has that shape, applied to a less obvious pair of families.
Theorem 2.55 (Even and odd subsets). For , the set has exactly as many even-sized subsets as odd-sized ones, namely of each. Equivalently, .
Proof. Let and be the families of even- and odd-sized subsets. Define by toggling the element :
Toggling changes the size by exactly , so it reverses parity and does map into . The same formula defines a map , and toggling twice restores , so is an involution and hence a bijection. Therefore , and since by the sum rule and the subset count, each is .
The alternating-sum form follows by grouping subsets by size: .∎
Remark. This is the combinatorial content of the cancellation used in the proof of the inclusion–exclusion principle, where for was obtained from the binomial theorem. The toggle involution replaces that algebra with a pairing, which is exactly the trade a bijective proof offers.
Pitfall. The hypothesis is essential and is exactly what makes a toggling element available. For there is one even-sized subset — the empty set — and no odd-sized one, so the conclusion is false. A bijective proof always breaks at the point where the map cannot be defined; finding that point is a good way to discover the hypothesis you forgot.
Stars and bars is the next: the number of solutions of in non-negative integers is . It is proved in Basic Counting, and proved there by precisely the bijection this section is about — write stars, a bar, stars, a bar, and so on, so that a solution becomes an arrangement of stars and bars, an arrangement being determined by which of the positions hold the bars. The formula is used in the example below without further comment.
Example 2.56 (Distributing identical objects). In how many ways can identical chocolates be divided among children, if a child may get none? And if every child must get at least one?
Solution. The first question is stars and bars with , : .
For the second, substitute with . The equation becomes , and the substitution is a bijection between the positive solutions of the first equation and the non-negative solutions of the second (its inverse subtracts one from each coordinate). So the count is .□
Theorem 2.57 (Conjugation of partitions). For all , the number of partitions of into at most parts equals the number of partitions of into parts each of size at most .
Proof. Represent a partition with by its Young diagram: left-justified rows of boxes, the -th row having boxes. Define the conjugate by reflecting the diagram in its main diagonal, so that is the number of rows with at least boxes — that is, the length of the -th column.
The reflected diagram is again a valid Young diagram: column lengths are weakly decreasing because the rows are weakly decreasing and left-justified. Reflection preserves the number of boxes, so is again a partition of . Reflecting twice returns the original diagram, so conjugation is an involution, hence a bijection on the partitions of .
Finally, conjugation exchanges the two conditions: has at most rows if and only if every column of has length at most , which is precisely the statement that every part of is at most . So conjugation restricts to a bijection between the two families in the statement.∎
Example 2.58 (Checking conjugation by hand). Verify the theorem for , .
Solution. Partitions of with at most parts: , , , — four of them.
Partitions of with every part at most : , , , — also four.
Conjugation matches them: , , , . Note that the bijection is between the two families, not a symmetry within one: only self-conjugate partitions are fixed.□
Theorem 2.59 (Ballot problem and Catalan numbers). The number of lattice paths from to using unit steps right and up that never rise above the diagonal is the Catalan number
Proof. A path from to consists of steps, of them right, and is determined by which steps are right; so there are paths in all.
Call a path bad if it touches the line at some point; the good paths are exactly the ones we want to count. We biject the bad paths with the paths from to .
Given a bad path, let be its first contact with the line and reflect the portion of the path before in that line. Reflection in sends to and exchanges right steps with up steps, so the reflected segment is again a lattice path; it now starts at the image of , namely , and still ends at . Leaving the rest of the path untouched gives a path from to .
The map is invertible. A path from to starts strictly above the line , since at the line has height , and ends strictly below it, since at the line has height ; a lattice path changing one coordinate by one at a time cannot get from one side to the other without landing on the line, so it meets the line. Reflecting its initial segment at the first contact returns a path from to that touches the line, hence a bad path, and the two reflections undo one another.
A path from to takes right steps and up steps, so there are of them. Hence the good paths number
using , which follows from the factorial expressions.∎
Intuition. The reflection principle is a sign-cancelling device in disguise. Bad paths are objects we want to discard; instead of discarding them one at a time, we match each with a path to a different endpoint, whose count we already know. Subtracting a known count is the same as cancelling, and the bijection is what licences it.
Example 2.61 (Balanced bracket sequences). Show that the number of sequences of opening and closing brackets in which every prefix has at least as many openings as closings is .
Solution. Map a bracket sequence to a lattice path by reading left to right: an opening bracket is a right step, a closing bracket an up step. A sequence with of each becomes a path from to , and the reverse reading recovers the sequence, so this is a bijection between bracket sequences and paths.
The prefix condition says that after any number of symbols, the closings so far do not exceed the openings — that is, the path's height never exceeds its horizontal position, so the path stays weakly below . By the previous theorem the count is .
This is the pattern for every Catalan bijection: find the map that turns a structural constraint into a geometric one, then count the geometry.□
Theorem 2.62 (Counting edges in two ways: Mantel's theorem). A graph on vertices with no triangle has at most edges.
Proof. Let be triangle-free with vertex set , , and edge set . For an edge , the neighbourhoods of and are disjoint: a common neighbour would make a triangle. Hence for every edge .
Sum this over all edges and count the left side in the other direction. Each vertex appears in the sum once for each incident edge, that is times, so
By the Cauchy–Schwarz inequality, or equivalently because the mean of squares is at least the square of the mean,
using the handshake lemma. Combining, , so .∎
Remark. The bound is attained by the complete bipartite graph with parts of sizes and , which has edges and no triangle, since any triangle would need two vertices in the same part and those are never adjacent. Mantel's theorem is the first case of Turán's theorem, and the proof above — count a quantity over edges, then over vertices — is the standard entry point into extremal graph theory.
2.9The Reach and the Limits of These Principles
Having seen the principles work, it is worth asking honestly what they do and do not deliver.
Bijections generalise for free. A bijection between two families usually respects more structure than the statement mentions, and each extra invariant it preserves upgrades the theorem. Conjugation of partitions was stated as an equality of two counts, but the map itself preserves the number of boxes, sends the largest part to the number of parts, and fixes exactly the self-conjugate partitions — three further theorems from one map.
Proposition 2.63 (A refinement conjugation gives for free). For every , the number of partitions of with largest part exactly and at most parts equals the number with exactly parts and largest part at most .
Proof. Conjugation is a bijection on partitions of which exchanges "largest part" with "number of parts": the largest part of is the length of the first row, which becomes the length of the first column of , that is the number of parts of . Applying this to both statistics in the statement gives the claim, since a bijection restricts to a bijection between subfamilies defined by corresponding conditions.∎
Sign-reversing involutions extend the method to identities with minus signs. A bijective proof of needs both sides to be counts of things. An identity such as has no such reading — until one builds a single set of signed objects and pairs off objects of opposite sign.
Method 2.64 (Proving an identity by a sign-reversing involution). To prove :
- Realise the alternating sum as a signed set , each object carrying a sign .
- Construct an involution on that reverses sign, defined on all of except a set of fixed points.
- Objects paired by cancel, so the sum reduces to the signed count of .
- Show -summing over gives — ideally is small and all of one sign.
Example 2.65 (An alternating identity by cancellation). Prove that for , , by exhibiting a sign-reversing involution.
Solution. Let be the set of all subsets of , with . Grouping by size shows , which is the sum in question.
Let toggle the element , as in the even/odd theorem. It is an involution on , it changes by and therefore reverses sign, and it has no fixed points, since and always differ. So is partitioned into pairs of opposite sign, every pair contributes , and the total is .
The hypothesis is what guarantees the element exists — the same place the argument must break, since for the sum is .□
Not everything has a nice bijection, and some equalities resist one for decades. The Rogers–Ramanujan identities — that the partitions of into parts differing by at least are equinumerous with those into parts congruent to or modulo — were proved analytically by Rogers in 1894, but a genuinely bijective proof (Garsia–Milne, 1981) took almost ninety years and is famously intricate. We state the identity without proof: its proof is far beyond this chapter, and rests on -series machinery rather than on anything developed here.
Remark. A word on honesty about scope. Three results in this chapter are quoted rather than proved from scratch: the binomial theorem (used once, to evaluate ), the Cauchy–Schwarz inequality (used once, in Mantel's theorem), and the alternating-series error bound (used to place near ). Each is standard and each is proved elsewhere in this corpus. Everything else above is proved where it is stated.
Pigeonhole proves existence and nothing more. This is a genuine limitation, not a stylistic one. The pigeonhole argument for Dirichlet's theorem shows a good rational approximation exists but offers no way to find it; continued fractions, a different technique entirely, produce it. Ramsey's theorem for guarantees a monochromatic triangle in a -edge colouring, and the proof even suggests where to look, but the corresponding guarantee for larger Ramsey numbers is spectacularly ineffective: is known only to lie between and , and Erdős's remark that humanity would do better to fight an alien demanding than to compute it remains apt.
Inclusion–exclusion is exact but can be computationally hopeless. The formula for sets has terms, so it is a practical tool only when the intersections have a closed form (as in the sieve, the derangement count and the surjection count) or when a truncation suffices. That truncation is exactly what the Bonferroni inequalities licence, and it is why the union bound — the crudest possible instance — is nevertheless one of the most used inequalities in probability and in the probabilistic method.
Pitfall. Inclusion–exclusion is a statement about finite cardinalities. For infinite sets it has no meaning as stated, since the terms are not numbers; the correct generalisation is to finite measures, where holds, and the proof is the same disjoint decomposition with in place of . Probability, where is a probability measure, is the most common such setting.
Summary. The chapter in one paragraph. The sum rule counts disjoint pieces; the product rule counts independent choices; both follow from the definition of cardinality as a listing. The bijection principle transports a count across a matching, and is the engine behind both rules. Pigeonhole is the sum rule read as an inequality: fibres cannot all be small, which yields existence theorems — Ramsey, Erdős–Szekeres, Dirichlet — whose conclusions are far stronger than their proofs are long. Inclusion–exclusion repairs the sum rule when the pieces overlap, and its complementary form counts objects avoiding a list of properties: the sieve, derangements, surjections. Double counting equates two decompositions of one set and yields identities — handshake, Vandermonde, hockey-stick, Mantel — with no algebra at all.
- Adding without checking disjointness. The sum rule requires . If the cases overlap, the answer is too big, and the fix is inclusion–exclusion, not a smaller estimate.
- Multiplying when the number of options depends on history. The sequential choice rule needs the count at each step to be constant. When it varies, split into cases and add.
- Forgetting the "+1". objects in boxes force no collision; do. Likewise the generalised threshold is , not .
- Quoting the generalised bound when supplies are limited. answers the unconstrained problem. If some box cannot hold objects, recompute the maximal blocking configuration and add one.
- Treating the ceiling form as a claim about every box. It bounds the fullest box only; other boxes may be empty, and you do not get to choose which box is full.
- Claiming a pigeonhole argument locates the collision. It proves existence. Which pair collides, and how to find it, are different questions needing different tools.
- Using where is needed. The multiples of and of intersect in the multiples of ; that is only when and are coprime.
- Getting the inclusion–exclusion signs wrong. The -fold intersections carry in the union form and in the complementary form. Confusing the two flips the whole answer.
- Stopping after the pairwise terms. Triples have been added three times and subtracted three times and would otherwise vanish; they must be added back.
- Accepting inconsistent intersection data. If the seven (or ) disjoint regions come out negative, no such sets exist and the formula's output is meaningless.
- Asserting a bijection without exhibiting it. "There is an obvious correspondence" is not a proof. Give the map, check that its output has the required property, and give the inverse.
- Forgetting to check the target. Half of all faulty bijective proofs define a perfectly good map whose outputs do not actually lie in the intended set.
- Confusing a bijection with an injection. An injection proves only. Both directions, or an explicit inverse, are needed for equality.
- Missing the degenerate case. Toggling arguments need an element to toggle, so they fail at ; largest-element arguments need the set to be non-empty. Check the smallest case.