Introduction

Combinatorics answers "how many?" without listing. How many passwords of a given form exist, how many ways can tasks be assigned to processors, how many paths cross a grid, how many binary strings avoid a pattern? Counting is the basis of discrete probability (favourable outcomes over total outcomes), of the analysis of algorithms (number of comparisons, number of possible inputs), and of many recurrences.

The topics are the basic principles, permutations and combinations with and without repetition, the binomial theorem, distributions of objects into boxes, inclusion-exclusion, derangements, the pigeonhole principle, and the Catalan numbers.

Prerequisites

  • Sets: union, intersection, complement, power set, Cartesian product.
  • Functions: injective, surjective and bijective maps; counting functions.
  • Notation: n!=n(n−1)⋯1n! = n(n-1)\cdots 1, 0!=10! = 1.

Core concepts

The basic principles

  • Sum rule. If a task can be done in one of mm ways or one of nn ways, with no way common to both, there are m+nm + n ways. (For disjoint sets, ∣A∪B∣=∣A∣+∣B∣|A \cup B| = |A| + |B|.)
  • Product rule. If a task is a sequence of two steps, with mm ways for the first and, for each of them, nn ways for the second, there are mnmn ways. (∣A×B∣=∣A∣∣B∣|A \times B| = |A||B|.)
  • Subtraction rule. ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B| when the cases overlap.
  • Complement rule. Count what you do not want and subtract from the total. For "at least one", use the complement.
  • Division rule. If every outcome of interest is counted exactly dd times, divide by dd. (Circular arrangements, unordered pairs.)
  • Bijection rule. If the objects can be put in one-to-one correspondence with objects that are easier to count, the counts are equal.

Permutations and combinations

Selection of rr from nn distinct objectsOrder mattersOrder does not matter
Without repetitionP(n,r)=n!(n−r)!P(n, r) = \dfrac{n!}{(n-r)!}(nr)=n!r! (n−r)!\binom{n}{r} = \dfrac{n!}{r!\,(n-r)!}
With repetition allowednrn^r(n+r−1r)\binom{n + r - 1}{r}

Here 0≤r≤n0 \le r \le n in the first row (otherwise the count is 0); in the second row any r≥0r \ge 0 is allowed.

  • (nr)\binom{n}{r} ("nn choose rr") counts rr-element subsets. P(n,r)=r!(nr)P(n, r) = r!\binom{n}{r}: choose the set, then order it.
  • Permutations of a multiset. The number of distinct arrangements of nn objects with n1n_1 of type 1, …\ldots, nkn_k of type kk (n1+⋯+nk=nn_1 + \cdots + n_k = n) 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!}.

Example: arrangements of MISSISSIPPI (1 M, 4 I, 4 S, 2 P) =11!/(1! 4! 4! 2!)=34650= 11!/(1!\,4!\,4!\,2!) = 34650.

  • Circular arrangements. nn distinct people around a round table, where rotations are the same: (n−1)!(n-1)!. If reflections are also the same (necklaces of distinct beads): (n−1)!/2(n-1)!/2 for n≥3n \ge 3.

The binomial theorem and identities

For any x,yx, y and integer n≥0n \ge 0:

(x+y)n=∑r=0n(nr)xn−ryr.(x + y)^n = \sum_{r=0}^{n} \binom{n}{r} x^{n-r} y^r .

Standard identities (all for integers n≥0n \ge 0, with (nr)=0\binom{n}{r} = 0 when r<0r < 0 or r>nr > n):

IdentityStatement
Symmetry(nr)=(nn−r)\binom{n}{r} = \binom{n}{n-r}
Pascal(nr)=(n−1r−1)+(n−1r)\binom{n}{r} = \binom{n-1}{r-1} + \binom{n-1}{r} for n≥1n \ge 1
Row sum∑r(nr)=2n\sum_r \binom{n}{r} = 2^n
Alternating sum∑r(−1)r(nr)=0\sum_r (-1)^r \binom{n}{r} = 0 for n≥1n \ge 1
Weighted sum∑rr(nr)=n2n−1\sum_r r\binom{n}{r} = n 2^{n-1}
Vandermonde∑k(mk)(nr−k)=(m+nr)\sum_k \binom{m}{k}\binom{n}{r-k} = \binom{m+n}{r}
Squares∑k(nk)2=(2nn)\sum_k \binom{n}{k}^2 = \binom{2n}{n}
Hockey stick∑i=rn(ir)=(n+1r+1)\sum_{i=r}^{n} \binom{i}{r} = \binom{n+1}{r+1}

The coefficient of xaybx^a y^b in (x+y)n(x + y)^n with a+b=na + b = n is (nb)\binom{n}{b}; in (x+y+z)n(x + y + z)^n the coefficient of xaybzcx^a y^b z^c is n!/(a! b! c!)n!/(a!\,b!\,c!).

Distributing objects into boxes (stars and bars)

Stars and bars. The number of solutions of x1+x2+⋯+xk=nx_1 + x_2 + \cdots + x_k = n in non-negative integers is

(n+k−1k−1).\binom{n + k - 1}{k - 1}.

Reason: arrange nn stars and k−1k - 1 bars in a row; the bars cut the stars into kk groups, possibly empty. Any arrangement is a choice of k−1k - 1 bar positions among n+k−1n + k - 1.

  • In positive integers (xi≥1x_i \ge 1): substitute yi=xi−1y_i = x_i - 1, giving (n−1k−1)\binom{n - 1}{k - 1}.
  • With lower bounds xi≥aix_i \ge a_i: subtract ∑ai\sum a_i from nn first.
  • With upper bounds xi≤bix_i \le b_i: use inclusion-exclusion over the variables that exceed their bounds (Example 3).
  • Inequality x1+⋯+xk≤nx_1 + \cdots + x_k \le n: add a slack variable xk+1≥0x_{k+1} \ge 0, giving (n+kk)\binom{n + k}{k}.
Stars and bars
Figure 1. The solution x1=2,x2=0,x3=3x_1 = 2, x_2 = 0, x_3 = 3 of x1+x2+x3=5x_1 + x_2 + x_3 = 5 as the row of 5 stars and 2 bars ⋆⋆∣∣⋆⋆⋆\star\star \mid\mid \star\star\star; there are (72)=21\binom{7}{2} = 21 such rows.

The twelvefold summary (the common cases). For n≥1n\ge1 and k≥1k\ge1, distributing nn objects into kk boxes:

ObjectsBoxesAny number per boxAt least one per boxAt most one per box
DistinctDistinctknk^nk! S(n,k)k!\,S(n, k)P(k,n)P(k, n)
IdenticalDistinct(n+k−1k−1)\binom{n + k - 1}{k - 1}(n−1k−1)\binom{n - 1}{k - 1}(kn)\binom{k}{n}
DistinctIdentical∑j=0kS(n,j)\sum_{j=0}^{k} S(n, j)S(n,k)S(n, k)1 if n≤kn \le k, else 0
IdenticalIdenticalpartitions of nn into at most kk partspartitions of nn into exactly kk parts1 if n≤kn \le k, else 0

With S(0,0)=1S(0,0)=1 and S(0,j)=0S(0,j)=0 for j>0j>0, S(n,k)S(n, k) is the Stirling number of the second kind, the number of ways to partition an nn-set into kk non-empty blocks, with S(n,k)=k S(n−1,k)+S(n−1,k−1)S(n, k) = k\,S(n-1, k) + S(n-1, k-1). k! S(n,k)=∑j=0k(−1)j(kj)(k−j)nk!\,S(n, k) = \sum_{j=0}^{k}(-1)^j\binom{k}{j}(k-j)^n is the number of onto functions (see Functions).

Inclusion-exclusion

For finite sets A1,…,AnA_1, \ldots, A_n:

∣⋃i=1nAi∣=∑i∣Ai∣−∑i<j∣Ai∩Aj∣+∑i<j<l∣Ai∩Aj∩Al∣−⋯+(−1)n+1∣A1∩⋯∩An∣.\Big|\bigcup_{i=1}^{n} A_i\Big| = \sum_{i} |A_i| - \sum_{i<j} |A_i \cap A_j| + \sum_{i<j<l} |A_i \cap A_j \cap A_l| - \cdots + (-1)^{n+1} |A_1 \cap \cdots \cap A_n| .

The number of elements in none of the sets is N−∣⋃Ai∣N - |\bigcup A_i|, where NN is the size of the universe. If every intersection of jj sets has the same size sjs_j (the symmetric case), the count of elements in none of them is ∑j=0n(−1)j(nj)sj\sum_{j=0}^{n} (-1)^j \binom{n}{j} s_j with s0=Ns_0 = N.

Inclusion-exclusion for three sets
Figure 2. A three-set Venn diagram with each of the 7 regions labelled by how many times it is counted by ∑∣Ai∣\sum|A_i|, by ∑∣Ai∩Aj∣\sum|A_i \cap A_j| and by ∣A1∩A2∩A3∣|A_1 \cap A_2 \cap A_3|; every region ends with net count 1.

Derangements

A derangement is a permutation with no fixed point (no element in its original position). Their number is

Dn=n!∑j=0n(−1)jj!,Dn=(n−1)(Dn−1+Dn−2),D0=1, D1=0.D_n = n! \sum_{j=0}^{n} \frac{(-1)^j}{j!}, \qquad D_n = (n - 1)(D_{n-1} + D_{n-2}), \quad D_0 = 1,\ D_1 = 0 .

Values: D1,…,D6=0,1,2,9,44,265D_1, \ldots, D_6 = 0, 1, 2, 9, 44, 265. DnD_n is the nearest integer to n!/en!/e for n≥1n \ge 1, so the probability that a random permutation is a derangement tends to 1/e≈0.36791/e \approx 0.3679. The number of permutations with exactly rr fixed points is (nr)Dn−r\binom{n}{r} D_{n-r}.

The pigeonhole principle

If NN objects go into kk boxes, some box holds at least ⌈N/k⌉\lceil N/k \rceil objects. To guarantee that some box holds at least rr objects, N=k(r−1)+1N = k(r - 1) + 1 objects are needed and enough.

Catalan numbers

Cn=1n+1(2nn)=(2nn)−(2nn+1),C0,…,C6=1,1,2,5,14,42,132.C_n = \frac{1}{n + 1}\binom{2n}{n} = \binom{2n}{n} - \binom{2n}{n+1}, \qquad C_0, \ldots, C_6 = 1, 1, 2, 5, 14, 42, 132 .

CnC_n counts: balanced strings of nn pairs of parentheses; binary trees with nn nodes (structurally distinct); full binary trees with n+1n + 1 leaves; ways to parenthesise a product of n+1n + 1 factors; lattice paths from (0,0)(0, 0) to (n,n)(n, n) with unit right and up steps that never go above the diagonal; triangulations of a convex (n+2)(n + 2)-gon; valid stack-permutation sequences of nn pushes and pops. They satisfy Cn+1=∑i=0nCiCn−iC_{n+1} = \sum_{i=0}^{n} C_i C_{n-i}.

Lattice paths without the diagonal restriction: from (0,0)(0, 0) to (a,b)(a, b) with right and up steps there are (a+ba)\binom{a + b}{a} paths.

Worked examples

Example 1: committees

From 6 men and 5 women, choose a committee of 4 with at least one woman. Total (114)=330\binom{11}{4} = 330; all-men (64)=15\binom{6}{4} = 15; answer 330−15=315330 - 15 = 315. (Adding "choose one woman, then any 3 others" gives 5(103)=6005\binom{10}{3} = 600, which overcounts.)

Example 2: strings

Binary strings of length 10 with exactly four 1s: (104)=210\binom{10}{4} = 210. With at least two 1s: 210−1−10=10132^{10} - 1 - 10 = 1013. Strings over {a,b,c}\{a, b, c\} of length 5 containing at least one aa: 35−25=2113^5 - 2^5 = 211.

Example 3: stars and bars with an upper bound

Number of non-negative integer solutions of x1+x2+x3=10x_1 + x_2 + x_3 = 10 with every xi≤4x_i \le 4. Without bounds: (122)=66\binom{12}{2} = 66. If x1≥5x_1 \ge 5, set x1′=x1−5x_1' = x_1 - 5: (72)=21\binom{7}{2} = 21 solutions; same for x2,x3x_2, x_3. Two variables cannot both be at least 5 unless the third is 0 and both equal 5: (22)=1\binom{2}{2} = 1 for each pair. Three: impossible.

66−3⋅21+3⋅1−0=6.66 - 3 \cdot 21 + 3 \cdot 1 - 0 = 6 .

(They are the arrangements of {4,4,2}\{4, 4, 2\} and {4,3,3}\{4, 3, 3\}: 3+3=63 + 3 = 6.)

Example 4: inclusion-exclusion on permutations

How many permutations of 1,2,…,61, 2, \ldots, 6 have none of the patterns "12", "34" or "56" as consecutive entries? Gluing jj of the three pairs into blocks leaves 6−j6 - j units, so each jj-fold intersection has (6−j)!(6 - j)! permutations:

720−3⋅120+3⋅24−6=426.720 - 3 \cdot 120 + 3 \cdot 24 - 6 = 426 .

Example 5: derangements

Five letters are placed at random into their five addressed envelopes. The number of ways in which no letter is in its correct envelope is D5=44D_5 = 44; exactly two correct: (52)D3=10⋅2=20\binom{5}{2} D_3 = 10 \cdot 2 = 20.

Important properties and observations

  • (nr)\binom{n}{r} is largest at r=⌊n/2⌋r = \lfloor n/2 \rfloor (and ⌈n/2⌉\lceil n/2 \rceil).
  • (nr)\binom{n}{r} counts rr-subsets, binary strings with rr ones, and monotone lattice paths with rr up-steps among nn steps; switching between these views solves many problems.
  • (n+r−1r)\binom{n + r - 1}{r} (combinations with repetition) equals the stars-and-bars count with nn types and rr items: choosing rr donuts from nn kinds.
  • Number of subsets of an nn-set with even size =2n−1= 2^{n-1} for n≥1n \ge 1.
  • Number of diagonals of a convex nn-gon: (n2)−n\binom{n}{2} - n. Number of intersection points of diagonals (no three concurrent): (n4)\binom{n}{4}.

GATE examination perspective

  • Identify the model first. Ordered or not, repetition or not, distinct or identical objects and boxes. Choose the row of the tables above first.
  • "At least" problems. Use complements; avoid "choose one, then the rest", which overcounts.
  • Equation-solution counts. Stars and bars, with inclusion-exclusion for upper bounds.
  • Derangements and Catalan numbers. Know the first values; recognise Catalan structures (balanced parentheses, binary trees, stack sequences).
  • Numerical-answer questions. Compute carefully; check with a smaller instance where you can list the cases.
  • Trap: circular arrangements: (n−1)!(n - 1)!, not n!n!; necklaces also divide by 2.

Summary

Sources

  1. K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., McGraw-Hill, 2012: Chapter 6 (Counting) and Sections 8.5 and 8.6 (Inclusion-Exclusion and its applications).

Next steps