Small principles that do a lot of work.

Pigeonhole principle

If items go into boxes and , some box holds at least two items.

Generalised: some box holds at least items.

Deceptively powerful. Typical uses:

ClaimArgument
Among any numbers from , one divides anotherwrite each as with odd; only odd values available
Some non-empty subset has sum divisible by the prefix sums mod ; two coincide (or one is 0)
Any sequence of distinct numbers has a monotone subsequence of length Erdős-Szekeres, via (increasing, decreasing) length pairs
Two of any 5 points in a unit square are within quarter the square
A repeated state must occur within stepsthe state space has size
Birthday collisionssee Birthday Paradox

The prefix-sum-mod- argument is the one that appears most often in contests: it constructively finds the subarray, not just proves existence.

Extremal principle

Consider the largest / smallest / leftmost object satisfying the property.

The workhorse of constructive proofs. “Take the shortest counterexample” and derive a contradiction; “take the heaviest edge on the cycle” and show it is removable (MST cycle property); “take the vertex of minimum degree” and induct.

Invariants and monovariants

  • Invariant — a quantity unchanged by every allowed move. If the start and target differ in it, the target is unreachable. (Parity, a sum mod , a colouring, a permutation’s sign.)
  • Monovariant — a quantity that only increases (or only decreases). Proves termination, and bounds the number of steps.

The classic: the 15-puzzle is solvable iff the permutation parity plus the blank’s row distance is even — a parity invariant.

Double counting

Count the same set two ways and equate. This proves:

More generally, it is how most combinatorial identities are proved and how many counting problems are solved — count the contribution of each element rather than each configuration. The edge-contribution trick for tree distances is exactly this.

Symmetry

  • If the problem is symmetric in some variables, the answer often is too — which lets you fix an ordering () and multiply by the number of arrangements.
  • Symmetry breaking in search: fix that element 0 goes in the first group. Cuts a factor.
  • Burnside’s lemma counts objects up to symmetry — see Burnside and Pólya.

Useful sums and bounds

SumClosed form
— the divisor-sum bound
(Stirling)

The harmonic bound is why “for each , loop over multiples of ” is — see Sieve Techniques.

Modular arithmetic reminders

Full treatment in Modular Arithmetic; the traps in one line each:

  • can be negative in C++ — write ((a - b) % m + m) % m.
  • Division needs a modular inverse, which exists only when .
  • reduces the exponent modulo , not .
  • long long overflows at ; two values near multiplied need __int128.

See also: Combinatorics · Proof Techniques · Constructive Algorithms