Search Knowledge

© 2026 LIBREUNI PROJECT

Combinatorics and Enumerative Analysis

Combinatorics and Enumerative Analysis

Combinatorics is the study of discrete structures. It determines the existence, count, and optimization of arrangements according to specific rules.

Fundamental Principles

  • Addition Principle: If events are mutually exclusive, sum the ways.
  • Multiplication Principle: If events occur in sequence, multiply the ways.

Permutations and Combinations

Permutations (P(n,k)P(n, k)): Choosing and ordering kk elements from nn. P(n,k)=n!(nk)!P(n, k) = \frac{n!}{(n-k)!}

Combinations ((nk)\binom{n}{k}): Choosing kk elements without regard to order. (nk)=n!k!(nk)!\binom{n}{k} = \frac{n!}{k!(n-k)!}

python
1import math
2 
3def nCr(n, r):
4 return math.comb(n, r)
5 
6def nPr(n, r):
7 return math.perm(n, r)
8 
9print(f"Combinations (10 choose 3): {nCr(10, 3)}")
10print(f"Permutations (10 permute 3): {nPr(10, 3)}")

Pascal’s Triangle and Binomial Expansion

The identity (nk)=(n1k1)+(n1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k} allows for recursive construction.

python
1def pascal_triangle(rows):
2 triangle = [[1]]
3 for i in range(1, rows):
4 row = [1]
5 for j in range(1, i):
6 row.append(triangle[i-1][j-1] + triangle[i-1][j])
7 row.append(1)
8 triangle.append(row)
9 return triangle
10 
11for row in pascal_triangle(6):
12 print(str(row).center(30))

Advanced Principles

  • Pigeonhole Principle: If n>mn > m items are put in mm boxes, one box has >1>1 item.
  • Inclusion-Exclusion: Corrects for overcounting in unions (AB=A+BAB|A \cup B| = |A| + |B| - |A \cap B|).

Which principle is best suited for counting the number of permutations where no element stays in its original position?

Stars and Bars: Multisets

Choosing kk items from nn types with repetition: (n+k1k)\binom{n+k-1}{k}.

python
1from itertools import combinations_with_replacement
2 
3# Choosing 2 items from {A, B, C} with repetition
4types = ['A', 'B', 'C']
5k = 2
6combos = list(combinations_with_replacement(types, k))
7print(f"Multisets of size {k} from {types}:")
8print(combos)
9print(f"Formula count: {nCr(len(types) + k - 1, k)}")

How many ways can you arrange 5 identical objects into 3 distinct bins (including empty bins)?

Previous Module Boolean Algebra