Combinatorics: counting, recurrence relations and generating functions
Permutations, combinations, stars and bars, pigeonhole, inclusion-exclusion, derangements and Catalan numbers, solving linear recurrences by characteristic roots, and using ordinary generating functions to count and to solve recurrences.
Sum rule: disjoint cases add. Product rule: independent stages multiply.
Bijection: if two sets correspond one-to-one, count whichever is easier.
Selecting from distinct objects
Order matters
Order does not matter
No repetition
Repetition allowed
More arrangements:
Multiset permutations: arrangements of objects with alike of one kind, of another, and so on: . Example: MISSISSIPPI gives .
Circular arrangements of distinct objects: ; if a mirror image counts as the same (a necklace), .
Lattice paths from to using unit right and up steps: .
Pigeonhole principle: placing objects into boxes forces some box to hold at least . To guarantee that some box holds objects you need objects.
Binomial theorem: . Useful identities:
, and the even-size and odd-size subsets each number ;
Pascal: ;
.
A monotone lattice path is a word in R and U, so paths from (0, 0) to (4, 3) are counted by choosing the positions of the U steps.
2. Stars and bars: distributing identical objects
The number of ways to put identical objects into distinct boxes equals the number of non-negative integer solutions of
which is . Think of stars and bars in a row: choose where the bars go.
Constraint
Count
(no empty box)
substitute , then
inclusion-exclusion on the boxes with
Upper bounds by inclusion-exclusion: for with each , subtract solutions where one variable is at least , add back those where two are, and so on.
Which model? Ask two questions: are the objects identical or distinct, and are the boxes identical or distinct?
Objects
Boxes
Count
distinct ()
distinct ()
distinct
distinct, none empty
(onto functions)
identical
distinct
stars and bars
distinct
identical, none empty
(Stirling, second kind)
Choosing items from types with repetition is also stars and bars: .
3. Inclusion-exclusion, derangements and Catalan numbers
Inclusion-exclusion for sets: . Count the complement ("none of the bad events") as total minus this.
Derangements: permutations of items with no item in its own place.
Values: , , , , , . For large , . The number of permutations with exactly fixed points is .
Catalan numbers:
They satisfy . counts:
binary trees with nodes (structurally different shapes), and so binary search trees on distinct keys;
balanced strings of pairs of parentheses;
lattice paths from to that never go above the diagonal;
stack-permutations of (orders obtainable by pushing in order and popping at will);
triangulations of a convex polygon with sides.
4. Solving linear recurrences
A linear homogeneous recurrence with constant coefficients of order :
Method: write the characteristic equation and find its roots.
Roots
General solution
distinct
repeated (twice)
with multiplicity
Then fix the constants from the initial values.
Non-homogeneous : solution = general homogeneous part + one particular solution. Guess the particular solution in the shape of :
constant : try a constant ;
: try , or if is a characteristic root.
Standard recurrences:
Problem
Recurrence
Solution
Tower of Hanoi moves
,
Bit strings of length with no "11"
, ,
Regions made by lines in general position
,
Fibonacci
roots
For the no-"11" strings: a valid string ends in 0 (any valid string of length before it) or in 10 (any valid string of length ).
5. Ordinary generating functions
The ordinary generating function of a sequence is . The coefficient of , written , is the answer to the counting question.
Sequence
Generating function
for , else 0
Counting with products: each box contributes a factor listing its allowed amounts, and the coefficient of in the product counts the distributions. Example: putting identical sweets into 3 boxes holding at most 2 each is .
Solving recurrences: multiply the recurrence by , sum over , solve for , then expand by partial fractions. For , : , so and .
Reading a generating function backwards is common too: , so .
Formulas to remember
Permutations and combinations
Multiset permutations
Stars and bars
Derangements
Catalan numbers
Distinct characteristic roots
Repeated characteristic root
Negative binomial series
Generalised pigeonholeSome box gets at least this many of objects in boxes
Common mistakes
Using when the question needs ; check by trying a tiny case.
Treating identical objects as distinct (or the reverse) when choosing the counting model.
For a repeated characteristic root, writing instead of .
Forgetting the add-back terms in inclusion-exclusion with upper bounds.
Counting circular arrangements as instead of .
Mis-indexing the no-consecutive-1s count: length 1 already has 2 valid strings.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Stars and bars with lower bounds
numerical
How many integer solutions does have with , , ?
Step 1: Remove the lower bounds by substitution.
Try it on paper first.
Example 2: A recurrence with a repeated root
numerical
Solve with , .
Step 1: Write and solve the characteristic equation.
Try it on paper first.
Example 3: Letters in the wrong envelopes
numerical
Four letters are put into four addressed envelopes, one each, at random. In how many ways does no letter reach its own envelope? In how many does exactly one?
Step 1: Set up inclusion-exclusion over the letters that land correctly.
Try it on paper first.
Example 4: Counting with a generating function
numerical
In how many ways can 4 identical sweets be given to 3 children if no child gets more than 2?
Step 1: Write the generating function.
Try it on paper first.
Previous year questions
21 official GATE CSE questions on this topic, newest first.
10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.