Folioby Interconnected
Log InSign Up

The many faces of the binomial coefficient: why nCr is so ubiquitous

Through Pascal's triangle, lattice paths, and the binomial theorem, we uncover the many identities of the binomial coefficient. We also cover the computational machinery essential for competitive programming: factorial tables with modular inverses, and Lucas' theorem for enormous indices.

FO
Folio Official
March 1, 2026

The binomial coefficient (rn​) begins life with the modest meaning "the number of ways to choose r objects from n." Yet it appears everywhere in mathematics: in Pascal's triangle, in lattice path enumeration, in the expansion of (x+y)n, and in modular arithmetic for competitive programming. Why is (rn​) so ubiquitous?

1 Definition and basic properties

Definition 1 (Binomial coefficient).
For non-negative integers n and r with 0≤r≤n, the binomial coefficient is
(rn​)=r!(n−r)!n!​.
When r>n, we set (rn​)=0.
Remark 2.
That (rn​) is always an integer is not obvious from the formula: a quotient of factorials need not be an integer in general. But from the combinatorial interpretation – the number of ways to choose r objects from n– it must be a non-negative integer. This tension between algebraic non-obviousness and combinatorial transparency is one of the charming features of the binomial coefficient.

2 Pascal's identity: the recursive structure

Theorem 3 (Pascal's identity).
For 1≤r≤n−1,
(rn​)=(r−1n−1​)+(rn−1​).
Proof.
Fix a particular element x among the n objects. Every r-element subset either contains x or does not.

If it contains x, we must choose the remaining r−1 elements from the other n−1 objects, giving (r−1n−1​) subsets.

If it does not contain x, all r elements come from the remaining n−1 objects, giving (rn−1​) subsets.

These two cases are mutually exclusive, so by the addition principle, (rn​)=(r−1n−1​)+(rn−1​). □
Remark 4.
Pascal's identity generates Pascal's triangle: each row lists (0n​),(1n​),…,(nn​), and every entry is the sum of the two entries directly above it. From a computational point of view, Pascal's triangle is nothing other than a DP table – a dynamic programming table whose recurrence is Pascal's identity, filled row by row.

3 Lattice paths

Theorem 5 (Lattice path count).
The number of shortest lattice paths from (0,0) to (a,b)– where each step moves one unit right or one unit up – is (aa+b​).
Proof.
A shortest path consists of exactly a rightward steps and b upward steps, in some order. The path is determined by choosing which a of the a+b total steps are rightward, so the count is (aa+b​). □
Example 6.
The number of shortest lattice paths from (0,0) to (3,2) is (35​)=10. Two such paths are RRUРУ and URRRУ (where R denotes right and U denotes up).
Remark 7.
The lattice path interpretation is remarkably powerful. Pascal's identity, in this language, says that any path reaching (a,b) arrives either from (a−1,b) (having taken a rightward step) or from (a,b−1) (having taken an upward step). The recurrence is nothing but the observation that every path has a last step.

4 The binomial theorem

Theorem 8 (Binomial theorem).
For any x,y and non-negative integer n,
(x+y)n=r=0∑n​(rn​)xryn−r.
Proof.
Expand (x+y)n=(x+y)(x+y)⋯(x+y) by choosing either x or y from each of the n factors and multiplying the choices together. The term xryn−r arises precisely when x is chosen from r of the n factors, and the number of ways to make that selection is (rn​). □
Example 9 (Special values).
Setting x=y=1 yields ∑r=0n​(rn​)=2n, which is the total number of subsets of an n-element set. Setting x=1,y=−1 yields ∑r=0n​(−1)r(rn​)=0, revealing that the number of even-sized subsets equals the number of odd-sized subsets.

5 Fast computation modulo a prime

In competitive programming, one frequently needs (rn​)modp where p is a prime (typically p=109+7).

Remark 10 (Factorial table with modular inverses).
The following preprocessing, done in O(n) time, enables O(1) queries:
  1. Build a factorial table: fact[i]=i!modp for i=0,1,…,n.

  2. Build an inverse factorial table: inv_fact[i]=(i!)−1modp, using Fermat's little theorem (ap−1≡1(modp) implies a−1≡ap−2(modp)).

Then (rn​)≡fact[n]⋅inv_fact[r]⋅inv_fact[n−r](modp), computed in O(1).

6 Lucas' theorem

Theorem 11 (Lucas' theorem).
Let p be a prime. Write n and r in base p: n=∑ni​pi and r=∑ri​pi. Then
(rn​)≡i∏​(ri​ni​​)(modp).
Remark 12.
Lucas' theorem is invaluable when n is astronomically large (say n>1018) but p is small. Each digit-level binomial coefficient (ri​ni​​) involves values less than p and can be computed without any precomputation. When p is large, however, the factorial-table method is usually more practical.

7 Takeaway

  • The binomial coefficient wears many hats: subset selection, lattice paths, polynomial expansion, set partition, and more.

  • Pascal's identity is the source of its recursive structure – and, equivalently, of the DP table known as Pascal's triangle.

  • The binomial theorem bridges algebra and combinatorics.

  • For computation modulo a prime, the factorial table with modular inverses handles most cases; Lucas' theorem covers extremely large indices with small primes.

In the next article, we investigate the curious "add, subtract, add, subtract..." pattern of the inclusion–exclusion principle and ask what makes the alternating signs give the right answer.

CombinatoricsMathematicsBetween the Lines
FO
Folio Official

Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.

1 followers·107 articles
Combinatorics — Between the LinesPart 2 of 8
Previous
What does it mean to count? Addition, multiplication, and surjections
Next
Inclusion--exclusion: why the alternating signs work

Share your expertise with the world

Write articles with LaTeX support, build your audience, and earn from your knowledge.

Start Writing — It's Free

More from Folio Official

Folio Official·March 1, 2026

Recurrences and generating functions: what happens when you turn a sequence into a function

A generating function is the "business card" of a sequence. Multiplication becomes convolution, and recurrences become algebraic equations. We derive the closed form for the Fibonacci numbers (Binet's formula) as a showcase of the method.

CombinatoricsMathematicsBetween the Lines
Folio Official·March 1, 2026

Combinatorics meets dynamic programming: when counting becomes computation

Dynamic programming is bottom-up evaluation of a recurrence; a generating function is its analytic closed form. We draw the correspondence between the knapsack DP and generating function multiplication, discuss convolution and FFT, and survey the connections across the entire series.

CombinatoricsMathematicsBetween the Lines
Folio Official·March 1, 2026

Inclusion--exclusion: why the alternating signs work

The inclusion--exclusion principle corrects for overcounting by alternately adding and subtracting intersection sizes. We prove the general formula using indicator functions, apply it to count derangements, and trace the thread forward to the Mobius inversion formula on partially ordered sets.

CombinatoricsMathematicsBetween the Lines
Folio Official·March 1, 2026

Counting under symmetry: Burnside's lemma and Polya's enumeration theorem

When objects related by rotation or reflection are considered identical -- as with necklaces -- naive counting fails. Using the language of group actions, Burnside's lemma reduces the problem to a clean formula: the number of distinct objects equals the average number of fixed points across the group.

CombinatoricsMathematicsBetween the Lines