TExcelTAD
Home › Discrete Mathematics › Binomial Coefficients and the Bookkeeper Rule

Binomial Coefficients and the Bookkeeper Rule

The number of kk-element subsets of an nn-element set is the binomial coefficient (nk)\binom{n}{k}, read "nn choose kk". It counts committees, lottery tickets, poker hands, bit strings with kk ones and lattice paths on a grid. Its generalization, the multinomial coefficient, counts arrangements of letters with repeats (the bookkeeper rule).

The formula and its symmetry

From the division rule:

(nk)=n!k! (n−k)!=n(n−1)⋯(n−k+1)k!\binom{n}{k} = \frac{n!}{k!\,(n-k)!} = \frac{n (n-1) \cdots (n-k+1)}{k!}

Symmetry: (nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k}, because choosing which kk to take is the same as choosing which n−kn - k to leave out (a bijection).

Question Answer
5-card poker hands from 52 cards (525)=2598960\binom{52}{5} = 2598960
lottery: 6 numbers from 49 (496)=13983816\binom{49}{6} = 13983816
bit strings of length 10 with exactly 3 ones (103)=120\binom{10}{3} = 120
shortest grid paths from (0,0)(0,0) to (4,3)(4,3) (right/up steps) (73)=35\binom{7}{3} = 35

The grid paths are 7 steps, of which you choose which 3 are "up": a bijection with 3-subsets of {1,…,7}\{1, \ldots, 7\}.

python · try it yourself
from math import comb
from itertools import combinations

print("C(52,5) =", comb(52, 5), " C(49,6) =", comb(49, 6))
bits = [s for s in range(2 ** 10) if bin(s).count("1") == 3]
print("10-bit strings with three 1s:", len(bits), "=", comb(10, 3))

def paths(x, y):
    if x == 0 or y == 0:
        return 1
    return paths(x - 1, y) + paths(x, y - 1)
print("grid paths to (4,3):", paths(4, 3), "=", comb(7, 3))
C(52,5) = 2598960  C(49,6) = 13983816
10-bit strings with three 1s: 120 = 120
grid paths to (4,3): 35 = 35

Pascal's triangle

Pascal's rule: (nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k} for 0<k<n0 < k < n.

Combinatorial proof: fix one element xx. A kk-subset either contains xx (choose the other k−1k - 1 from n−1n - 1) or does not (choose all kk from the other n−1n - 1). The cases are disjoint, so add (sum rule). ■\blacksquare

The rule builds Pascal's triangle row by row, using only additions, which is how programs compute binomial coefficients without huge factorials:

python · try it yourself
row = [1]
for n in range(9):
    print(f"n={n}: " + " ".join(f"{x:3d}" for x in row))
    row = [1] + [row[i] + row[i + 1] for i in range(len(row) - 1)] + [1]
n=0:   1
n=1:   1   1
n=2:   1   2   1
n=3:   1   3   3   1
n=4:   1   4   6   4   1
n=5:   1   5  10  10   5   1
n=6:   1   6  15  20  15   6   1
n=7:   1   7  21  35  35  21   7   1
n=8:   1   8  28  56  70  56  28   8   1

The bookkeeper rule (multinomials)

If a sequence has nn letters made of n1n_1 copies of letter 1, n2n_2 of letter 2, ..., nkn_k of letter kk, the number of distinct arrangements is the multinomial coefficient

(nn1,n2,…,nk)=n!n1! n2!⋯nk!\binom{n}{n_1, n_2, \ldots, n_k} = \frac{n!}{n_1!\, n_2! \cdots n_k!}

The word COMMITTEE has C, O, I once, M, T, E twice: 9!2! 2! 2!=45360\frac{9!}{2!\,2!\,2!} = 45360 arrangements. The same number counts ways to split a set into labelled groups of given sizes: splitting 10 developers into a team of 5, a team of 3 and a team of 2 can be done in 10!5! 3! 2!=2520\frac{10!}{5!\,3!\,2!} = 2520 ways. With only two kinds of letters, the multinomial is the binomial: (nk,n−k)=(nk)\binom{n}{k, n-k} = \binom{n}{k}.

python · try it yourself
from math import factorial
from collections import Counter

def multinomial(word):
    out = factorial(len(word))
    for c in Counter(word).values():
        out //= factorial(c)
    return out

for w in ["COMMITTEE", "BOOKKEEPER", "ABRACADABRA"]:
    print(w, multinomial(w))
print("teams of 5, 3, 2 from 10:", factorial(10) // (factorial(5) * factorial(3) * factorial(2)))
COMMITTEE 45360
BOOKKEEPER 151200
ABRACADABRA 83160
teams of 5, 3, 2 from 10: 2520

Poker probabilities

With equally likely hands, probability = favourable hands / all hands. A full house (three of one rank, two of another): choose the rank of the triple (13), its 3 suits ((43)\binom{4}{3}), the rank of the pair (12 remaining), its 2 suits ((42)\binom{4}{2}):

13⋅(43)⋅12⋅(42)=3744,P=37442598960≈0.0014413 \cdot \binom{4}{3} \cdot 12 \cdot \binom{4}{2} = 3744, \qquad P = \frac{3744}{2598960} \approx 0.00144

Order matters for the two ranks here (a triple of kings with a pair of 7s differs from a triple of 7s with a pair of kings), so we use 13 and 12, not (132)\binom{13}{2}.

In software

math.comb and itertools.combinations are the tools. Binomial coefficients size test matrices (choosing kk of nn feature flags), estimate collisions, appear in the binomial distribution of probability, and count the paths a dynamic-programming grid algorithm must consider.

Exercises

Exercise 1: Committees with roles

From 12 people, choose a committee of 4 with one chair among them. How many ways?

Answer
Solution

Choose the 4 members, then the chair among them: (124)⋅4=495⋅4=1980\binom{12}{4} \cdot 4 = 495 \cdot 4 = 1980. Alternatively choose the chair first (12 ways), then 3 more members: 12(113)=12⋅165=198012 \binom{11}{3} = 12 \cdot 165 = 1980.

Exercise 2: Two pairs

How many 5-card hands are "two pair" (two cards of one rank, two of another, and a fifth card of a third rank)?

Answer
Solution

Here the two pair ranks are interchangeable, so choose them as a set: (132)\binom{13}{2}. Suits for each pair: (42)2\binom{4}{2}^2. The fifth card: any of the 52−8=4452 - 8 = 44 cards of other ranks.

(132)(42)2⋅44=78⋅36⋅44=123552\binom{13}{2} \binom{4}{2}^2 \cdot 44 = 78 \cdot 36 \cdot 44 = 123552

Exercise 3: Verify by brute force (code)

Count full houses by enumerating all (525)\binom{52}{5} hands? That is 2.6 million hands: feasible but slow in a browser. Instead verify the method on a small deck with 5 ranks and 4 suits.

Answer

5⋅4⋅4⋅6=4805 \cdot 4 \cdot 4 \cdot 6 = 480, and brute force agrees.

Solution
python · try it yourself
from itertools import combinations
from collections import Counter
from math import comb

deck = [(r, s) for r in range(5) for s in range(4)]
brute = sum(1 for hand in combinations(deck, 5)
            if sorted(Counter(r for r, _ in hand).values()) == [2, 3])
print(brute, 5 * comb(4, 3) * 4 * comb(4, 2))
480 480

Test yourself

What is (82)\binom{8}{2}?

  1. 16
  2. 28
  3. 56
  4. 64

Which identity is Pascal's rule?

  1. (nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k}
  2. (nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}
  3. (nk)=nk\binom{n}{k} = n^k
  4. (nk)=nk\binom{n}{k} = \frac{n}{k}

How many distinct arrangements does AABBB have?

  1. 10
  2. 20
  3. 60
  4. 120