βˆ‘GateAndNet
Practice MCQs
GATE CS / Engineering Mathematics & Discrete Math
Edit
INTERMEDIATEπŸ”₯ High-Yield Exam Topic 4 min read 3 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\}
🚨 Exam Trap Alert

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!).

πŸ“ Quick Revision Formula Sheet
Non-Negative Integer Solutions (Stars & Bars)
(n+rβˆ’1rβˆ’1)\binom{n + r - 1}{r - 1}
πŸ’‘ 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)
πŸ’‘ 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}
πŸ’‘ Counts unlabeled BSTs, valid parenthesis strings, and stack-sortable permutations
#Discrete Math#Combinatorics#Pigeonhole#Derangements#Catalan#GATE CS

🎯 Practice PYQs on This Topic (1)

Q1.GATE CS Discrete MathMCQMEDIUM
+2 Marks β€’ -0.67 Neg

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\}?

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