Counting by Correspondence
Paths from to that never go above number : reflect each bad path across after its first touch to get a bijection with all paths to .
A bijection is a proof when both the map and its inverse are described and shown to land in the right set; "reflect" must come with "and the reflected path ends at , and reflecting again recovers the original". Catalan numbers count triangulations, parenthesizations, and non-crossing matchings by the same recurrence — an answer of or is a strong hint that Catalan is behind it.
Non-attacking rook placements on an board are permutations; forbidding the main diagonal gives derangements , and forbidding neighbors around a circle of people gives a matching count by inclusion–exclusion over the cycle's edges: with .
Inclusion–exclusion over a STRUCTURED family (the edges of a cycle, the diagonal cells) needs the count of pairwise-compatible forbidden objects — for a cycle that is the number of -matchings, a Lucas-number-like quantity. Write the general term, compute separately, and only then assemble the alternating sum.
Subsets of whose size equals their minimum number : sum over , a shallow diagonal of Pascal's triangle. Subsets with no two consecutive elements number .
Two proofs to know: the diagonal identity by Pascal's rule (both sides satisfy the Fibonacci recurrence), and the tiling bijection (squares and dominoes). When a count comes out Fibonacci, one of these is the intended proof.
How many sequences of H's and T's have every prefix containing at least as many H's as T's?
Show the answerHide the answer
.
Bijections Built and Checked
To prove by correspondence, define and , check that each lands in the right set, and check and . Equivalently: show is well defined, injective and surjective.
Finite sets have the same size exactly when a bijection exists, so a bijective proof is as rigorous as any computation — provided both directions are verified. The inverse map is the part people skip, and it is usually where a wrong “bijection” breaks: the forward map is often obviously defined, but two different objects can go to the same image, or some target is never reached. Writing explicitly forces you to decode, which is exactly the check that the encoding lost no information.
A composition of is an ordered sum of positive integers equal to ( and are different compositions of ). How many compositions of have parts, and how many are there in all?
Step 1 — write as a row of dots; there are gaps between neighbours. A composition with parts is the same thing as a choice of gaps in which to place bars: is .
Step 2 — the maps: composition bar positions , a -subset of because the parts are positive; conversely a subset gives the parts , all positive. The maps undo each other.
Step 3 — so there are compositions with parts and in all; for , .
How to find it. Ordered sums of positive integers are cut points on a line. Positivity of the parts is exactly the condition that the cuts are distinct.
Prove that the number of partitions of into distinct parts equals the number of partitions of into odd parts. (Euler; the bijection is Glaisher’s.)
Step 1 — the map from distinct to odd: write each part as with odd and replace it by copies of . The result has only odd parts and the same sum.
Step 2 — the map from odd to distinct: if the odd part occurs times, write in binary, with distinct 's, and replace the copies by the parts . These are distinct: parts built from the same have different powers of , and parts built from different odd have different odd parts.
Step 3 — they are inverse, because binary representation is unique: grouping the parts of a distinct partition by their odd part , the powers of that occur are distinct, so they are the binary digits of the number of copies of that produces. For : , , , , , — six on each side.
How to find it. “Distinct” and “any multiplicity” are related by binary expansion; “odd” is what is left after removing powers of . Every number is uniquely (power of ) (odd).
Prove that there are trees on the vertex set ().
Step 1 — encoding. Given a tree, repeatedly delete the leaf with the smallest label and write down its neighbour; stop when two vertices remain. The result is a sequence of length with entries in : the Prüfer code. For the tree with edges the leaves removed are and the code is .
Step 2 — what the code remembers: a vertex of degree appears exactly times (it is written once for each neighbour deleted before it, and it is itself deleted or survives with one edge left). So the leaves of the tree are exactly the labels absent from the code.
Step 3 — decoding. At step , the leaf deleted was the smallest label that has not been deleted yet and does not occur among the remaining entries (those are the vertices that still have an edge to lose); it was joined to . After steps join the two labels left. This rebuilds the edges one by one, so decoding inverts encoding.
Step 4 — conversely, every sequence decodes to a tree: each step joins a vertex that will never be used again to one that is still present, so no cycle forms, and edges on vertices without a cycle form a tree, whose code is the sequence we started from. Hence trees and sequences are in bijection: of each. For that is .
How to find it. counts sequences of length over symbols; the question is which canonical order of tearing down a tree records it. “Smallest leaf first” makes the order reconstructible.
A tempting proof of Cayley: “root the tree at and send it to the function giving each other vertex its parent; there are functions from to ...” — which would give trees, and for that is , not . The map from functions back to trees is not well defined: the function with and describes a -cycle, not a tree, and so does every function with a cycle. Of the functions for , only the that avoid cycles come from trees. A “bijection” checked in one direction only is a map, not a count.
Which tree on has Prüfer code ?
Show the answerHide the answer
Step 1: the smallest label not in is : edge –. Remaining code , used : smallest label not in and not used is : edge –. Remaining , used : smallest free label not equal to is : edge –. The labels left are and : edge –. The tree has edges ; vertex has degree and appears twice in the code, vertex has degree and appears once, as Step 2 of Example 3 predicts. Encoding it again: delete (write ), then (write ), then (write ) — the code is ✓.
Generating Functions and the Roots-of-Unity Filter
If , the product has = the number of subsets of with sum . For a primitive -th root of unity ,
Expanding the product chooses, for each , either (leave out) or (put it in), and multiplies: each subset contributes . For the filter, is when and otherwise (a geometric series with ratio sums to ). So averaging over keeps exactly the coefficients with . The work in a problem is evaluating , and the identity is what usually does it.
In how many ways can be paid with coins of values , and (order irrelevant)?
Step 1 — the generating function is : the three geometric series choose how many coins of each value.
Step 2 — extract the coefficient of by the number of s. For , pay with s and s: the number of s is , six ways. For , pay : or twos, three ways. For : one way. Total .
How to find it. Unlimited supply of each item is a geometric series; the coefficient is extracted by conditioning on the largest item, which leaves a simpler series.
How many subsets of (including the empty set) have a sum divisible by ?
Step 1 — , and we want with .
Step 2 — . For , is again a primitive fifth root, and as runs over , runs over all five fifth roots twice. So .
Step 3 — from at : , so , and .
Step 4 — the count is .
How to find it. “Sum divisible by ” is a filter on the coefficients of a subset-sum generating function; the set is two full cycles of residues mod , which is what makes the product collapse.
Let be an odd prime. Find the number of -element subsets of whose sum is divisible by . (IMO 1995/6.)
Step 1 — track size and sum at once: . The answer is the sum of the coefficients of over , i.e. with .
Step 2 — : , contributing .
Step 3 — : runs through all -th roots twice, so . From with and odd, . So , contributing .
Step 4 — the answer is . For this is , for it is — both confirmed by listing.
How to find it. Two constraints (size , sum ) mean two variables. Put the constraint you filter by roots of unity in , and read the other off as a coefficient in .
“The subsets of are spread evenly over the five residues of their sums, so the answer to Example 2 is .” That is not even an integer; the filter shows the true split is subsets with sum and for each other residue, because . Equidistribution is a conclusion that needs for , never an assumption. A second slip: averaging and filters by parity (), not by divisibility by .
How many subsets of have a sum divisible by ?
Show the answerHide the answer
. With , the exponents cover each residue mod twice, so . Since , this is . The count is .