The vote count
An election just ended. Candidate A got 7 votes. Candidate B got 3 votes. A wins, obviously.
But here's the question competition organizers love: if you shuffle the ballots and count them one at a time, what's the probability A is ahead after every single ballot?
A must lead at every step of the count, not just at the end.
Simulate it. Shuffle the ballots and watch A's lead over time:
After many trials, the fraction where A leads at every step converges to .
A random walk in disguise
Each ballot counted is a step. An A-ballot moves the tally up by 1. A B-ballot moves it down by 1. The count traces a random walk starting at 0, ending at .
The ballot problem asks: among all the walks from 0 to using up-steps and down-steps, what fraction never touch or cross zero?
If candidate A receives votes and candidate B receives votes with , the probability that A is strictly ahead of B throughout the counting is:
Catalan numbers: counting valid paths
Zoom out from the ballot problem for a moment. Consider paths on a grid: you take steps right-and-up and steps right-and-down, for steps total, starting and ending at height 0. How many of these paths never dip below the x-axis?
These are called Dyck paths, and the answer involves one of the most famous sequences in combinatorics.
The th Catalan number counts the number of paths from to using up-steps and down-steps that never go below zero:
The first few values: .
Generate random paths and see how many stay non-negative:
The fraction of valid paths matches . But how do you prove that?
The reflection principle
Here's the argument.
Take any "bad" path, one that dips below zero. Find the first point where it hits . Now reflect everything after that point across the line . Every up-step becomes a down-step and vice versa.
Every "bad" path (solid) that dips below zero corresponds to a unique reflected path (dashed) ending at -2. This bijection counts the bad paths exactly.
This reflection creates a bijection (a one-to-one correspondence) between:
- Bad paths from to that touch
- All paths from to
The reflection principle turns a hard counting problem ("paths that avoid ") into an easy one ("paths ending at a different point"). This is a bijection, a story proof in disguise.
Where these ideas appear
The ballot problem and Catalan numbers come up everywhere in competitions and programming:
Math competitions:
- IMO 2001 Problem 6 used lattice path arguments
- Putnam regularly features ballot-type counting problems
- USAMO/AIME problems on counting paths in grids
Programming contests:
- Codeforces/AtCoder problems on counting valid bracket sequences (Catalan numbers count these too)
- LeetCode #22 "Generate Parentheses" is the Catalan number in disguise
- Google Code Jam has included random walk probability problems
The Catalan number counts all of these:
| Object | Connection |
|---|---|
| Valid bracket sequences of length | Open = up, close = down |
| Binary trees with nodes | Left child = up, right child = down |
| Triangulations of an -gon | Each diagonal = a step |
| Stack-sortable permutations of | Push = up, pop = down |
The takeaway
Random walks reveal structure in sequential processes. The ballot problem's formula, the reflection principle's bijection trick, and Catalan numbers' ubiquity all stem from one idea: counting lattice paths with constraints. When a competition problem involves sequential choices that must satisfy some running condition, think walks, think reflections, think Catalan.