Combinatorics, Pigeonhole Principle, Inclusion-Exclusion & Generating Functions
Stars-and-bars integer solutions, Generalized Pigeonhole Principle, Derangements, Catalan numbers, and Ordinary Generating Functions for linear recurrences.
1. Counting Mappings Between Finite Sets
Let and . Counting functions is a guaranteed 1- or 2-mark question in GATE CS and UGC NET:
| Function Class | Condition | Exact Count Formula |
|---|---|---|
| Total Functions | Unrestricted | |
| Injective (One-to-One) | (0 if ) | |
| Surjective (Onto) | ||
| Bijective |
Generalized Pigeonhole Principle: If objects are placed into boxes, then at least one box contains at least objects. Conversely, to guarantee at least objects of the same type among types, pick objects.
2. Stars and Bars & Derangements
The number of non-negative integer solutions to () is:
If every variable must be strictly positive (), substitute to obtain .
Derangements (): Permutations of elements where no element stays in its original position ( for all ):
3. Catalan Numbers & Ordinary Generating Functions
The sequence () simultaneously counts:
- Number of structurally distinct Binary Search Trees (BSTs) with keys
- Number of valid balanced parenthesizations of pairs
- Number of ways to parenthesize a product of matrices (Matrix Chain Multiplication)
- Number of stack-sortable permutations of
Labeled vs Unlabeled Binary Trees: Unlabeled binary trees with nodes = . Labeled binary trees with distinct nodes = (whereas BSTs with distinct keys = because the inorder traversal is fixed!).
π― Practice PYQs on This Topic (1)
How many structurally distinct Binary Search Trees (BSTs) can be formed using distinct keys ?