Updated
In this lesson
Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.
Ballot problem
You will learn: Count paths that maintain a strict or weak lead under the chosen tie rule.
Start with: Events and probability
Candidate A receives a votes and candidate B receives b votes, with a > b so A wins. The ballots are counted one at a time in a uniformly random order. What is the probability that A is strictly ahead of B throughout the entire counting process?
The answer is beautifully simple:
The initial 0–0 tie is excluded from both checks. A tie after any vote defeats the strict rule but is allowed by the weak rule. With equal final totals, strict success is impossible while weak success can occur.
Enumerate all distinct vote orders
48 of 120 equally likely A/B orders meet the selected rule: 0.400000. Repeated same-candidate ballots are not treated as distinct vote strings. Showing page 1 of 6.
| Order | Lead after each vote | Pass? |
|---|---|---|
| AAAAAAABBB | 1, 2, 3, 4, 5, 6, 7, 6, 5, 4 | Yes |
| AAAAAABABB | 1, 2, 3, 4, 5, 6, 5, 6, 5, 4 | Yes |
| AAAAAABBAB | 1, 2, 3, 4, 5, 6, 5, 4, 5, 4 | Yes |
| AAAAAABBBA | 1, 2, 3, 4, 5, 6, 5, 4, 3, 4 | Yes |
| AAAAABAABB | 1, 2, 3, 4, 5, 4, 5, 6, 5, 4 | Yes |
| AAAAABABAB | 1, 2, 3, 4, 5, 4, 5, 4, 5, 4 | Yes |
| AAAAABABBA | 1, 2, 3, 4, 5, 4, 5, 4, 3, 4 | Yes |
| AAAAABBAAB | 1, 2, 3, 4, 5, 4, 3, 4, 5, 4 | Yes |
| AAAAABBABA | 1, 2, 3, 4, 5, 4, 3, 4, 3, 4 | Yes |
| AAAAABBBAA | 1, 2, 3, 4, 5, 4, 3, 2, 3, 4 | Yes |
| AAAABAAABB | 1, 2, 3, 4, 3, 4, 5, 6, 5, 4 | Yes |
| AAAABAABAB | 1, 2, 3, 4, 3, 4, 5, 4, 5, 4 | Yes |
| AAAABAABBA | 1, 2, 3, 4, 3, 4, 5, 4, 3, 4 | Yes |
| AAAABABAAB | 1, 2, 3, 4, 3, 4, 3, 4, 5, 4 | Yes |
| AAAABABABA | 1, 2, 3, 4, 3, 4, 3, 4, 3, 4 | Yes |
| AAAABABBAA | 1, 2, 3, 4, 3, 4, 3, 2, 3, 4 | Yes |
| AAAABBAAAB | 1, 2, 3, 4, 3, 2, 3, 4, 5, 4 | Yes |
| AAAABBAABA | 1, 2, 3, 4, 3, 2, 3, 4, 3, 4 | Yes |
| AAAABBABAA | 1, 2, 3, 4, 3, 2, 3, 2, 3, 4 | Yes |
| AAAABBBAAA | 1, 2, 3, 4, 3, 2, 1, 2, 3, 4 | Yes |
What to notice
- Blue trajectories satisfy the selected lead rule. With the default strict rule, ties after a vote fail; with the weak rule, ties are permitted.
- Change a and b and the theoretical probability updates immediately; the simulation fluctuates around it.
- With a=7, b=3: P = (7−3)/(7+3) = 40%. With a=9, b=1: P = 80%.
The reflection principle
The proof uses the reflection principle, a beautiful geometric argument. Consider all ballot sequences as lattice paths from (0,0) to (a+b, a−b). We want paths that stay strictly above the x-axis after step 0.
A successful sequence must start with A. Remove that first vote. The remaining path starts at height 1, contains a−1 upward steps and b downward steps, and must avoid height 0.
There are C(a+b−1, a−1) paths that start with A. For a bad path among them, reflect the segment up to its first visit to zero. This maps the remaining path to one starting at height −1 and ending at a−b. Such a path has a upward steps and b−1 downward steps, so there are C(a+b−1, a) bad paths starting with A.
Subtracting gives C(a+b−1, a−1) − C(a+b−1, a). Divide by all C(a+b, a) ballot orders, including those starting with B. The two terms become a/(a+b) and b/(a+b), yielding (a−b)/(a+b).
For a=3 and b=2, there are ten possible orders and just two remain strictly ahead: AAABB and AABAB. Allowing ties would give a different count. This distinction is why the first vote must be treated explicitly.
History and connections
The reflection principle used in ballot problems reappears throughout probability:
- Pricing barrier options in finance
- Calculating ruin probabilities for random walks
- Proving the arc-sine law for Brownian motion
The Gambler’s ruin problem is closely related — both deal with first-passage times in random walks.
Allow ties and count a different event
If a ≥ b, the probability that A is never behind is:
The initial tie before any votes is excluded from the strict check. At a=3,b=2, exactly two of ten orders have a strict lead, while five never fall below zero. The table lists every order for at most 12 total votes and exposes the lead after each vote. Pagination changes the displayed rows, not the denominator.
With a=b=2, no order can be strictly ahead after the final vote. But AABB and ABAB never fall behind, giving weak probability 2/6 = 1/3. With no B votes, both rules have probability one.
Make a prediction
For a=3,b=2, does ABAAB pass the strict rule?
Explore the answer
No. Its lead sequence is 1,0,1,2,1, so it ties after the second vote. It does pass the weak rule, which permits that zero.
Reflect the first step below zero
There are C(a+b,b) unconstrained A/B orders. For the weak rule, a bad path first reaches −1. Reflect its prefix through that first visit, exchanging A and B there. Because the original prefix contains one more B than A, the reflected full sequence has a+1 A votes and b−1 B votes. The mapping is reversible at the first visit to +1 in the reflected path.
Thus the bad count is C(a+b,b−1), and the good fraction is , yielding the weak formula. For b=0 there are no bad paths. This reflection differs from the earlier strict argument, which removes a required initial A and excludes later visits to zero.
Make a prediction
Does the formula apply if all A ballots are counted before every B ballot?
Explore the answer
No. The model assigns equal probability to every distinct order with the given totals. A fixed or geographically structured counting order changes that probability model; the formula is not an election-night forecasting rule.
Reference
Random Services: random walks and the ballot problem develops the strict result and its conditional random-walk interpretation. The weak-lead reflection and finite enumeration above make the changed boundary convention explicit.