1. The Taxonomy of Combinatorial Selections
When selecting $r$ items from a set of $n$ distinct objects, the mathematical formula depends on two fundamental axes:
- Order: Does the sequence matter? (Permutations vs Combinations).
- Repetition: Can an object be selected more than once? (With vs Without replacement).
text
2. Permutations & Multiset Arrangements
2.1 Permutations Without Replacement
An ordered arrangement of $r$ distinct elements chosen from $n$ distinct elements:
$$P(n, r) = n \times (n - 1) \times (n - 2) \times \dots \times (n - r + 1) = \frac{n!}{(n - r)!}$$
2.2 Multiset Permutations (Permutations with Indistinguishable Objects)
How many distinct strings can be formed by rearranging the letters in $\text{MISSISSIPPI}$?
Total letters $n = 11$: $1 \text{ M}, 4 \text{ I}, 4 \text{ S}, 2 \text{ P}$.
If all letters were distinct, there would be $11!$ permutations. But permuting the $4$ identical $\text{I}$'s among themselves produces identical strings ($4!$ identical duplicates).
Theorem:
The number of distinct permutations of $n$ objects where $n_1$ are of type 1, $n_2$ of type 2, ..., $n_k$ of type $k$ (with $\sum n_i = n$) is the Multinomial Coefficient:
$$\binom{n}{n_1, n_2, \dots, n_k} = \frac{n!}{n_1! , n_2! \cdots n_k!}$$
For $\text{MISSISSIPPI}$:
$$\frac{11!}{1! \times 4! \times 4! \times 2!} = \frac{39,916,800}{1 \times 24 \times 24 \times 2} = 34,650 \text{ distinct anagrams.}$$
3. Combinations: Unordered Selections
The number of ways to choose an unordered subset of $r$ elements from $n$ distinct elements:
$$\binom{n}{r} = C(n, r) = \frac{P(n, r)}{r!} = \frac{n!}{r!(n - r)!}$$
Key Symmetries & Identities:
- Complementary Symmetry: $$\binom{n}{r} = \binom{n}{n - r}$$ (Choosing $r$ elements to include is identical to choosing $n - r$ elements to leave behind).
- Pascal's Identity: $$\binom{n}{r} = \binom{n - 1}{r - 1} + \binom{n - 1}{r}$$ Combinatorial Proof: Focus on element $x_n$. Any subset of size $r$ either includes $x_n$ (must choose remaining $r-1$ from $n-1$) or excludes $x_n$ (must choose all $r$ from $n-1$). $\blacksquare$
4. Combinations with Replacement: Stars and Bars
How many ways can you distribute $r$ identical computational tasks across $n$ distinct server worker threads?
Equivalently: How many non-negative integer solutions exist for:
$$x_1 + x_2 + \dots + x_n = r, \quad \text{where } x_i \ge 0$$
The Geometric Stars and Bars Encoding
Represent the $r$ identical tasks as Stars ($\star$), and use $n - 1$ vertical Bars ($|$) to partition them into $n$ bins:
text
Any valid distribution corresponds to a distinct arrangement of $r$ stars and $n - 1$ bars.
Total positions in the sequence:
$$\text{Total symbols} = r + (n - 1)$$
To form a configuration, we simply choose which $r$ positions will be stars (or which $n - 1$ positions will be bars):
$$\binom{n + r - 1}{r} = \binom{n + r - 1}{n - 1}$$
Positive Integer Solutions ($x_i \ge 1$):
If every server must receive at least 1 task, pre-assign 1 task to each of the $n$ servers ($r' = r - n$). The remaining $r - n$ tasks are distributed freely:
$$\binom{(r - n) + n - 1}{n - 1} = \binom{r - 1}{n - 1}$$
5. The Binomial & Multinomial Theorems
5.1 The Binomial Theorem
For any real numbers $x, y$ and non-negative integer $n$:
$$(x + y)^n = \sum_{k=0}^n \binom{n}{k} x^{n - k} y^k$$
Combinatorial Proof:
$$(x + y)^n = \underbrace{(x + y)(x + y)\cdots(x + y)}_{n \text{ factors}}$$
When expanding the product, each term chooses either $x$ or $y$ from each factor. The term $x^{n-k} y^k$ arises whenever we choose $y$ from exactly $k$ factors (and $x$ from the remaining $n - k$). There are $\binom{n}{k}$ ways to make this choice. $\blacksquare$
5.2 Classic Binomial Sum Corollaries:
- Setting $x = 1, y = 1$: $$\sum_{k=0}^n \binom{n}{k} = \binom{n}{0} + \binom{n}{1} + \dots + \binom{n}{n} = 2^n \quad (\text{Total subsets in power set } \mathcal{P}(A))$$
- Setting $x = 1, y = -1$: $$\sum_{k=0}^n (-1)^k \binom{n}{k} = 0 \implies \sum_{k \text{ even}} \binom{n}{k} = \sum_{k \text{ odd}} \binom{n}{k} = 2^{n - 1}$$
6. Vandermonde's Identity
For non-negative integers $m, n, r$:
$$\binom{m + n}{r} = \sum_{k=0}^r \binom{m}{k} \binom{n}{r - k}$$
Combinatorial Proof:
Suppose a committee of $r$ software engineers must be formed from a department of $m$ frontend developers and $n$ backend developers.
The total number of committees is $\binom{m + n}{r}$.
Alternatively, we can partition by the number $k$ of frontend developers chosen ($0 \le k \le r$): choose $k$ frontend engineers ($\binom{m}{k}$) and remaining $r - k$ backend engineers ($\binom{n}{r - k}$). Summing over all possible $k$ yields the identical total. $\blacksquare$
7. Python Implementation: Stars and Bars & Binomial Expansion
python
8. Key Takeaways
- Permutations vs Combinations: Permutations track order ($P(n, r)$); combinations discard order ($C(n, r) = P(n, r)/r!$).
- Stars and Bars: Solves selections with replacement and linear Diophantine sum equations via $\binom{n + r - 1}{r}$.
- Binomial Identities: $\sum_{k=0}^n \binom{n}{k} = 2^n$ directly counts total subsets in the power set.