Bijections, Homothety & Structured Counting

Study Sheet

Bijections, Homothety & Structured Counting

Reflection, rooks and derangements, Fibonacci diagonals, matchings by inclusion–exclusion, homothety in figures

Counting by Correspondence

Tip
The reflection bijection
(0,0)(4,4)(3,5)y = x + 1
A path that reaches the line y = x + 1 (solid) and its tail reflected in that line (dashed), which ends at (3, 5).

Paths from (0,0)(0,0) to (n,n)(n,n) that never go above y=xy = x number (2nn)−(2nn−1)=Cn\binom{2n}{n} - \binom{2n}{n-1} = C_n: reflect each bad path across y=x+1y = x + 1 after its first touch to get a bijection with all paths to (n−1,n+1)(n-1, n+1).

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 (n−1,n+1)(n-1, n+1), and reflecting again recovers the original". Catalan numbers count triangulations, parenthesizations, and non-crossing matchings by the same recurrence — an answer of 132132 or 429429 is a strong hint that Catalan is behind it.

Tip
Rooks, permutations, and forbidden positions

Non-attacking rook placements on an n×nn\times n board are permutations; forbidding the main diagonal gives derangements Dn=n!∑k≤n(−1)k/k!D_n = n!\sum_{k\le n}(-1)^k/k!, and forbidding neighbors around a circle of 2n2n people gives a matching count by inclusion–exclusion over the cycle's edges: ∑k(−1)kmk(2n−2k−1)!!\sum_k(-1)^km_k(2n - 2k - 1)!! with mk=2n2n−k(2n−kk)m_k = \tfrac{2n}{2n-k}\binom{2n-k}{k}.

Inclusion–exclusion over a STRUCTURED family (the edges of a cycle, the diagonal cells) needs the count mkm_k of kk pairwise-compatible forbidden objects — for a cycle that is the number of kk-matchings, a Lucas-number-like quantity. Write the general term, compute mkm_k separately, and only then assemble the alternating sum.

Tip
Fibonacci diagonals and subset conditions

Subsets of {1..n}\{1..n\} whose size equals their minimum number FnF_n: sum (n−kk−1)\binom{n-k}{k-1} over kk, a shallow diagonal of Pascal's triangle. Subsets with no two consecutive elements number Fn+2F_{n+2}.

Two proofs to know: the diagonal identity ∑j(n−jj)=Fn+1\sum_j\binom{n-j}{j} = F_{n+1} 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.

Try it
Try it: Catalan by reflection

How many sequences of 55 H's and 55 T's have every prefix containing at least as many H's as T's?

Show the answer

(105)−(104)=252−210=42=C5\binom{10}{5} - \binom{10}{4} = 252 - 210 = 42 = C_5.

Bijections Built and Checked

Theorem
A bijection is two maps and two checks

To prove ∣A∣=∣B∣|A| = |B| by correspondence, define φ:A→B\varphi: A \to B and ψ:B→A\psi: B \to A, check that each lands in the right set, and check ψ(φ(a))=a\psi(\varphi(a)) = a and φ(ψ(b))=b\varphi(\psi(b)) = b. Equivalently: show φ\varphi 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 ψ\psi explicitly forces you to decode, which is exactly the check that the encoding lost no information.

Example
Example 1: compositions and bars
gaps chosen: 2 and 3 of the 5 gaps
The composition 2 + 1 + 3 of 6: two bars in the five gaps between six dots.

A composition of nn is an ordered sum of positive integers equal to nn (2+1+32 + 1 + 3 and 3+1+23 + 1 + 2 are different compositions of 66). How many compositions of nn have kk parts, and how many are there in all?

Step 1 — write nn as a row of nn dots; there are n−1n - 1 gaps between neighbours. A composition with kk parts is the same thing as a choice of k−1k - 1 gaps in which to place bars: 2+1+32 + 1 + 3 is ∙∙ ∣ ∙ ∣ ∙∙∙\bullet\bullet\,|\,\bullet\,|\,\bullet\bullet\bullet.

Step 2 — the maps: composition (c1,…,ck)↦(c_1, \ldots, c_k) \mapsto bar positions {c1,c1+c2,…,c1+⋯+ck−1}\{c_1, c_1 + c_2, \ldots, c_1 + \cdots + c_{k-1}\}, a (k−1)(k-1)-subset of {1,…,n−1}\{1, \ldots, n - 1\} because the parts are positive; conversely a subset p1<⋯<pk−1p_1 < \cdots < p_{k-1} gives the parts p1,p2−p1,…,n−pk−1p_1, p_2 - p_1, \ldots, n - p_{k-1}, all positive. The maps undo each other.

Step 3 — so there are (n−1k−1)\binom{n-1}{k-1} compositions with kk parts and ∑k(n−1k−1)=2n−1\sum_k\binom{n-1}{k-1} = 2^{n-1} in all; for n=6n = 6, 3232.

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.

Example
Example 2: distinct parts and odd parts

Prove that the number of partitions of nn into distinct parts equals the number of partitions of nn into odd parts. (Euler; the bijection is Glaisher’s.)

Step 1 — the map φ\varphi from distinct to odd: write each part as 2jm2^j m with mm odd and replace it by 2j2^j copies of mm. The result has only odd parts and the same sum.

Step 2 — the map ψ\psi from odd to distinct: if the odd part mm occurs rr times, write rr in binary, r=2j1+2j2+⋯r = 2^{j_1} + 2^{j_2} + \cdots with distinct jj's, and replace the rr copies by the parts 2j1m,2j2m,…2^{j_1}m, 2^{j_2}m, \ldots. These are distinct: parts built from the same mm have different powers of 22, and parts built from different odd mm 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 mm, the powers of 22 that occur are distinct, so they are the binary digits of the number of copies of mm that φ\varphi produces. For n=8n = 8: 8↦188 \mapsto 1^8,   7+1↦7+1\;7 + 1 \mapsto 7 + 1,   6+2↦3+3+1+1\;6 + 2 \mapsto 3 + 3 + 1 + 1,   5+3↦5+3\;5 + 3 \mapsto 5 + 3,   5+2+1↦5+1+1+1\;5 + 2 + 1 \mapsto 5 + 1 + 1 + 1,   4+3+1↦3+15\;4 + 3 + 1 \mapsto 3 + 1^5 — 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 22. Every number is uniquely (power of 22) ×\times (odd).

Example
Example 3: Cayley’s formula by Prüfer codes
123456
Leaves 1, 2, 3, 4 are deleted in that order, writing 4, 4, 5, 5.

Prove that there are nn−2n^{n-2} trees on the vertex set {1,2,…,n}\{1, 2, \ldots, n\} (n≥2n \ge 2).

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 n−2n - 2 with entries in {1,…,n}\{1, \ldots, n\}: the Prüfer code. For the tree with edges 14,24,45,35,5614, 24, 45, 35, 56 the leaves removed are 1,2,3,41, 2, 3, 4 and the code is (4,4,5,5)(4, 4, 5, 5).

Step 2 — what the code remembers: a vertex of degree dd appears exactly d−1d - 1 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 ii, the leaf deleted was the smallest label that has not been deleted yet and does not occur among the remaining entries ci,…,cn−2c_i, \ldots, c_{n-2} (those are the vertices that still have an edge to lose); it was joined to cic_i. After n−2n - 2 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 n−1n - 1 edges on nn vertices without a cycle form a tree, whose code is the sequence we started from. Hence trees and sequences are in bijection: nn−2n^{n-2} of each. For n=6n = 6 that is 12961296.

How to find it. nn−2n^{n-2} counts sequences of length n−2n - 2 over nn symbols; the question is which canonical order of tearing down a tree records it. “Smallest leaf first” makes the order reconstructible.

Side note
Where it goes wrong

A tempting proof of Cayley: “root the tree at 11 and send it to the function giving each other vertex its parent; there are nn−1n^{n-1} functions from {2,…,n}\{2, \ldots, n\} to {1,…,n}\{1, \ldots, n\}...” — which would give nn−1n^{n-1} trees, and for n=3n = 3 that is 99, not 33. The map from functions back to trees is not well defined: the function with 2↦32 \mapsto 3 and 3↦23 \mapsto 2 describes a 22-cycle, not a tree, and so does every function with a cycle. Of the 99 functions for n=3n = 3, only the 33 that avoid cycles come from trees. A “bijection” checked in one direction only is a map, not a count.

Try it
Try it: decode a Prüfer code

Which tree on {1,2,3,4,5}\{1, 2, 3, 4, 5\} has Prüfer code (3,3,1)(3, 3, 1)?

Show the answer

Step 1: the smallest label not in (3,3,1)(3, 3, 1) is 22: edge 22–33. Remaining code (3,1)(3, 1), used {2}\{2\}: smallest label not in {3,1}\{3, 1\} and not used is 44: edge 44–33. Remaining (1)(1), used {2,4}\{2, 4\}: smallest free label not equal to 11 is 33: edge 33–11. The labels left are 11 and 55: edge 11–55. The tree has edges 23,34,13,1523, 34, 13, 15; vertex 33 has degree 33 and appears twice in the code, vertex 11 has degree 22 and appears once, as Step 2 of Example 3 predicts. Encoding it again: delete 22 (write 33), then 44 (write 33), then 33 (write 11) — the code is (3,3,1)(3, 3, 1) ✓.

Generating Functions and the Roots-of-Unity Filter

Theorem
Coefficients count, roots of unity sort

If F(x)=∑kakxkF(x) = \sum_k a_kx^k, the product ∏j(1+xsj)\prod_{j}(1 + x^{s_j}) has aka_k = the number of subsets of {sj}\{s_j\} with sum kk. For a primitive mm-th root of unity ω\omega,

∑k≡0 (mod m)ak=1m∑j=0m−1F(ωj).\sum_{k \equiv 0 \ (\mathrm{mod}\ m)} a_k = \frac1m\sum_{j=0}^{m-1}F(\omega^j).

Expanding the product chooses, for each jj, either 11 (leave sjs_j out) or xsjx^{s_j} (put it in), and multiplies: each subset contributes xits sumx^{\text{its sum}}. For the filter, ∑j=0m−1ωjk\sum_{j=0}^{m-1}\omega^{jk} is mm when m∣km \mid k and 00 otherwise (a geometric series with ratio ωk≠1\omega^k \ne 1 sums to ωkm−1ωk−1=0\tfrac{\omega^{km} - 1}{\omega^k - 1} = 0). So averaging F(ωj)F(\omega^j) over jj keeps exactly the coefficients with m∣km \mid k. The work in a problem is evaluating F(ωj)F(\omega^j), and the identity ∏r=0m−1(x−ωr)=xm−1\prod_{r=0}^{m-1}(x - \omega^r) = x^m - 1 is what usually does it.

Example
Example 1: making change

In how many ways can 1010 be paid with coins of values 11, 22 and 55 (order irrelevant)?

Step 1 — the generating function is 1(1−x)(1−x2)(1−x5)\dfrac{1}{(1 - x)(1 - x^2)(1 - x^5)}: the three geometric series choose how many coins of each value.

Step 2 — extract the coefficient of x10x^{10} by the number cc of 55s. For c=0c = 0, pay 1010 with 11s and 22s: the number of 22s is 0,…,50, \ldots, 5, six ways. For c=1c = 1, pay 55: 0,10, 1 or 22 twos, three ways. For c=2c = 2: one way. Total 6+3+1=106 + 3 + 1 = 10.

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.

Example
Example 2: subset sums divisible by 5

How many subsets of {1,2,…,10}\{1, 2, \ldots, 10\} (including the empty set) have a sum divisible by 55?

Step 1 — F(x)=∏k=110(1+xk)F(x) = \prod_{k=1}^{10}(1 + x^k), and we want 15∑j=04F(ωj)\tfrac15\sum_{j=0}^4F(\omega^j) with ω=e2πi/5\omega = e^{2\pi i/5}.

Step 2 — F(1)=210=1024F(1) = 2^{10} = 1024. For j=1,…,4j = 1, \ldots, 4, ωj\omega^j is again a primitive fifth root, and as kk runs over 1,…,101, \ldots, 10, ωjk\omega^{jk} runs over all five fifth roots twice. So F(ωj)=(∏r=04(1+ωr))2F(\omega^j) = \left(\prod_{r=0}^4(1 + \omega^r)\right)^2.

Step 3 — from ∏r(x−ωr)=x5−1\prod_r(x - \omega^r) = x^5 - 1 at x=−1x = -1: ∏r(−1−ωr)=−2\prod_r(-1 - \omega^r) = -2, so ∏r(1+ωr)=(−1)5(−2)=2\prod_r(1 + \omega^r) = (-1)^5(-2) = 2, and F(ωj)=4F(\omega^j) = 4.

Step 4 — the count is 15(1024+4⋅4)=10405=208\tfrac15(1024 + 4\cdot4) = \tfrac{1040}{5} = 208.

How to find it. “Sum divisible by mm” is a filter on the coefficients of a subset-sum generating function; the set {1,…,10}\{1, \ldots, 10\} is two full cycles of residues mod 55, which is what makes the product collapse.

Example
Example 3: p-element subsets of 1, …, 2p

Let pp be an odd prime. Find the number of pp-element subsets of {1,2,…,2p}\{1, 2, \ldots, 2p\} whose sum is divisible by pp. (IMO 1995/6.)

Step 1 — track size and sum at once: G(x,y)=∏k=12p(1+yxk)G(x, y) = \prod_{k=1}^{2p}(1 + yx^k). The answer is the sum of the coefficients of ypxsy^px^s over p∣sp \mid s, i.e. 1p∑j=0p−1[yp] G(ωj,y)\tfrac1p\sum_{j=0}^{p-1}[y^p]\,G(\omega^j, y) with ω=e2πi/p\omega = e^{2\pi i/p}.

Step 2 — j=0j = 0: G(1,y)=(1+y)2pG(1, y) = (1 + y)^{2p}, contributing (2pp)\binom{2p}{p}.

Step 3 — j≠0j \ne 0: ωjk\omega^{jk} runs through all pp-th roots twice, so G(ωj,y)=(∏r=0p−1(1+yωr))2G(\omega^j, y) = \left(\prod_{r=0}^{p-1}(1 + y\omega^r)\right)^2. From ∏r(x−ωr)=xp−1\prod_r(x - \omega^r) = x^p - 1 with x=−1yx = -\tfrac1y and pp odd, ∏r(1+yωr)=1+yp\prod_r(1 + y\omega^r) = 1 + y^p. So G(ωj,y)=1+2yp+y2pG(\omega^j, y) = 1 + 2y^p + y^{2p}, contributing 22.

Step 4 — the answer is 1p((2pp)+2(p−1))=(2pp)−2p+2\dfrac1p\left(\binom{2p}{p} + 2(p - 1)\right) = \dfrac{\binom{2p}{p} - 2}{p} + 2. For p=3p = 3 this is 88, for p=5p = 5 it is 5252 — both confirmed by listing.

How to find it. Two constraints (size pp, sum ≡0\equiv 0) mean two variables. Put the constraint you filter by roots of unity in xx, and read the other off as a coefficient in yy.

Side note
Where it goes wrong

“The 10241024 subsets of {1,…,10}\{1, \ldots, 10\} are spread evenly over the five residues of their sums, so the answer to Example 2 is 1024/51024/5.” That is not even an integer; the filter shows the true split is 208208 subsets with sum ≡0\equiv 0 and 204204 for each other residue, because F(ω)≠0F(\omega) \ne 0. Equidistribution is a conclusion that needs F(ωj)=0F(\omega^j) = 0 for j≠0j \ne 0, never an assumption. A second slip: averaging F(1)F(1) and F(−1)F(-1) filters by parity (m=2m = 2), not by divisibility by 55.

Try it
Try it: sums divisible by 3

How many subsets of {1,2,3,4,5,6}\{1, 2, 3, 4, 5, 6\} have a sum divisible by 33?

Show the answer

F(1)=64F(1) = 64. With ω=e2πi/3\omega = e^{2\pi i/3}, the exponents 1,…,61, \ldots, 6 cover each residue mod 33 twice, so F(ω)=F(ω2)=((1+1)(1+ω)(1+ω2))2F(\omega) = F(\omega^2) = \left((1 + 1)(1 + \omega)(1 + \omega^2)\right)^2. Since (1+ω)(1+ω2)=1+ω+ω2+1=1(1 + \omega)(1 + \omega^2) = 1 + \omega + \omega^2 + 1 = 1, this is 22=42^2 = 4. The count is 13(64+4+4)=24\tfrac13(64 + 4 + 4) = 24.