GateMCQSCIENTIFIC PREP LAB
PlanSign Up
INTERMEDIATEFrequently Tested 4 min read 20 views

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 ∣A∣=m|A| = m and ∣B∣=n|B| = n. Counting functions f:A→Bf: A \to B is a guaranteed 1- or 2-mark question in GATE CS and UGC NET:

Function ClassConditionExact Count Formula
Total FunctionsUnrestrictednmn^m
Injective (One-to-One)m≤nm \le nP(n,m)=n!(n−m)!P(n, m) = \frac{n!}{(n-m)!} (0 if m>nm > n)
Surjective (Onto)m≥nm \ge n∑k=0n(−1)k(nk)(n−k)m=n! S(m,n)\sum_{k=0}^{n} (-1)^k \binom{n}{k}(n-k)^m = n! \, S(m, n)
Bijectivem=nm = nn!n!
Key Formula

Generalized Pigeonhole Principle: If NN objects are placed into kk boxes, then at least one box contains at least ⌈N/k⌉\lceil N / k \rceil objects. Conversely, to guarantee at least rr objects of the same type among kk types, pick k(r−1)+1k(r - 1) + 1 objects.

2. Stars and Bars & Derangements

The number of non-negative integer solutions to x1+x2+⋯+xr=nx_1 + x_2 + \dots + x_r = n (xi≥0x_i \ge 0) is:

(n+r−1r−1)\binom{n + r - 1}{r - 1}

If every variable must be strictly positive (xi≥1x_i \ge 1), substitute yi=xi−1≥0y_i = x_i - 1 \ge 0 to obtain (n−1r−1)\binom{n - 1}{r - 1}.

Derangements (DnD_n): Permutations of nn elements where no element stays in its original position (π(i)≠i\pi(i) \neq i for all ii):

Dn=(n−1)(Dn−1+Dn−2),D1=0,  D2=1,  D3=2,  D4=9,  D5=44D_n = (n-1)(D_{n-1} + D_{n-2}), \quad D_1 = 0,\; D_2 = 1,\; D_3 = 2,\; D_4 = 9,\; D_5 = 44

3. Catalan Numbers & Ordinary Generating Functions

The sequence Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n} (1,1,2,5,14,42,132,…1, 1, 2, 5, 14, 42, 132, \dots) simultaneously counts:

  • Number of structurally distinct Binary Search Trees (BSTs) with nn keys
  • Number of valid balanced parenthesizations of nn pairs
  • Number of ways to parenthesize a product of n+1n+1 matrices (Matrix Chain Multiplication)
  • Number of stack-sortable permutations of {1,2,…,n}\{1, 2, \dots, n\}
Common Exam Mistake

Labeled vs Unlabeled Binary Trees: Unlabeled binary trees with nn nodes = CnC_n. Labeled binary trees with nn distinct nodes = n!⋅Cnn! \cdot C_n (whereas BSTs with nn distinct keys = CnC_n because the inorder traversal is fixed!).

Key Formulas Summary
Non-Negative Integer Solutions (Stars & Bars)
(n+r−1r−1)\binom{n + r - 1}{r - 1}
Note: Number of solutions to x_1 + x_2 + ... + x_r = n with x_i >= 0
Derangements D_n (Zero Fixed Points)
Dn=n!∑k=0n(−1)kk!≈round⁡ ⁣(n!e)D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!} \approx \operatorname{round}\!\left(\frac{n!}{e}\right)
Note: D_1=0, D_2=1, D_3=2, D_4=9, D_5=44
nth Catalan Number
Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}
Note: Counts unlabeled BSTs, valid parenthesis strings, and stack-sortable permutations
#Discrete Math#Combinatorics#Pigeonhole#Derangements#Catalan#GATE CS

Practice Questions on This Chapter (2)

Q1GATE CS Discrete MathMCQMEDIUM
+2M • -0.67

How many structurally distinct Binary Search Trees (BSTs) can be formed using 55 distinct keys {10,20,30,40,50}\{10, 20, 30, 40, 50\}?

⚡ Click an option above to verify instantly
Q2GATE CS 2020NATMEDIUM
+2M • 0 Neg

A matrix A∈R3×3A \in \mathbb{R}^{3 \times 3} has trace tr⁡(A)=12\operatorname{tr}(A) = 12, determinant det⁡(A)=48\det(A) = 48, and one of its eigenvalues is λ1=4\lambda_1 = 4. What is the largest eigenvalue of AA?

Previous TopicGraph Theory Masterclass: Handshaking, Euler/Planar Formulas & ColoringNext Topic Relations, Equivalence Classes, POSETs, Lattices & Group Theory