Skip to content
GATEiit

GATE CSE · Engineering Mathematics

Sets, relations, functions, partial orders and lattices

Set operations and inclusion-exclusion, properties and counts of relations, equivalence relations, types and counts of functions, partial orders and Hasse diagrams, and lattices (bounded, complemented, distributive).

Before you start

  • Logic and quantifiers →

    Every property of a relation is a quantified statement, for example transitivity is ∀a,b,c.

  • Basic counting →

    Counting relations and functions is choosing, for each pair or element, one of a few options.

This topic comes before: Combinatorics: counting, recurrence relations and generating functions, Data flow analyses: constant propagation, liveness analysis and common subexpression elimination, ER model, Graphs: connectivity, matching and colouring, Integrity constraints and normal forms, Monoids and groups, Propositional and first-order logic, Regular and context-free languages; pumping lemma, Regular expressions and finite automata, Relational model: relational algebra, tuple calculus and SQL, Turing machines and undecidability, Counting: permutations and combinations, Functions of a single variable, Probability axioms, sample space, events, independent and mutually exclusive events

Concept notes

1. Sets and inclusion-exclusion

A set is an unordered collection of distinct elements. Key operations: union A∪B, intersection A∩B, difference A−B, complement A‾, symmetric difference A⊕B=(A−B)∪(B−A), and Cartesian product A×B with ∣A×B∣=∣A∣ ∣B∣.

The power set P(A) is the set of all subsets; ∣P(A)∣=2∣A∣.

Inclusion-exclusion counts a union: ∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣B∩C∣−∣A∩C∣+∣A∩B∩C∣ In general, add single sets, subtract pairs, add triples, and so on with alternating signs.

Countability. A set is countable if it is finite or in bijection with N. Z, Q, N×N, the set of all finite strings over a finite alphabet, and any countable union of countable sets are countable. R, any interval of R, P(N) and the set of all functions N→{0,1} are uncountable (Cantor's diagonal argument). For any set, ∣P(A)∣>∣A∣.

2. Relations and their properties

A relation on a set A is a subset R⊆A×A. With ∣A∣=n there are n2 ordered pairs, so 2n2 relations.

Property Condition Count on n elements
Reflexive (a,a)∈R for all a 2n(n−1)
Irreflexive (a,a)∉R for all a 2n(n−1)
Symmetric (a,b)∈R⇒(b,a)∈R 2n(n+1)/2
Antisymmetric (a,b),(b,a)∈R⇒a=b 2n⋅3n(n−1)/2
Asymmetric (a,b)∈R⇒(b,a)∉R 3n(n−1)/2
Reflexive and symmetric both 2n(n−1)/2
Transitive (a,b),(b,c)∈R⇒(a,c)∈R no simple formula

How the counts arise: split the n2 pairs into n diagonal pairs and n(n−1)/2 unordered off-diagonal pairs {a,b}. For antisymmetry each off-diagonal pair has 3 choices: neither, only (a,b), or only (b,a). The diagonal is free (2 choices each).

Antisymmetric does not mean "not symmetric": the empty relation and the identity relation are both symmetric and antisymmetric.

The transitive closure of R is the smallest transitive relation containing it, R+=R∪R2∪⋯∪Rn (Warshall's algorithm computes it).

3. Equivalence relations and partitions

An equivalence relation is reflexive, symmetric and transitive. Each element a has an equivalence class [a]={x:xRa}. Two classes are either equal or disjoint, so the classes form a partition of A. Conversely every partition gives an equivalence relation. So:

  • number of equivalence relations on n elements = number of partitions = the Bell number Bn: B1=1,B2=2,B3=5,B4=15,B5=52.
  • number with exactly k classes = the Stirling number of the second kind S(n,k), with S(n,k)=k S(n−1,k)+S(n−1,k−1) and Bn=∑kS(n,k).

If the classes have sizes c1,…,ck, the relation contains ∑ci2 ordered pairs.

Standard example: congruence modulo m on Z, a≡b(modm) when m∣(a−b). It has m classes [0],[1],…,[m−1].

Checks to remember:

  • the union of two equivalence relations need not be transitive, so need not be an equivalence;
  • the intersection of two equivalence relations is always an equivalence.

4. Functions

A function f:A→B assigns each element of A exactly one element of B.

  • Injective (one-one): f(a1)=f(a2)⇒a1=a2.
  • Surjective (onto): every b∈B is f(a) for some a.
  • Bijective: both. Only a bijection has an inverse f−1.

Counting with ∣A∣=m, ∣B∣=n:

Kind Count Condition
All functions nm
Injective n(n−1)⋯(n−m+1) m≤n
Surjective ∑k=0n(−1)k(nk)(n−k)m m≥n
Bijective n! m=n

The surjection count also equals n! S(m,n).

Composition g∘f (f first):

  • f,g injective ⇒g∘f injective; same for surjective.
  • g∘f injective ⇒f injective (g need not be).
  • g∘f surjective ⇒g surjective (f need not be).

For a finite set mapped to itself, injective, surjective and bijective are the same thing. By the pigeonhole principle, if m>n no function A→B is injective.

5. Partial orders and Hasse diagrams

A partial order ⪯ is reflexive, antisymmetric and transitive; (A,⪯) is a poset. Examples: ⊆ on a power set, divisibility ∣ on positive integers, ≤ on numbers. If every two elements are comparable, it is a total (linear) order.

A Hasse diagram draws a below b with an edge when b covers a (a≺b with nothing in between). Reflexive loops and transitive edges are left out.

Term Meaning
Minimal / maximal nothing strictly below / above it
Least / greatest below / above every element (unique if it exists)
Upper bound of S an element above every member of S
LUB (join, a∨b) the least upper bound
GLB (meet, a∧b) the greatest lower bound

A finite poset always has at least one minimal and one maximal element, but may have no least or greatest element. A greatest element is the only maximal element, but a unique maximal element need not be greatest in an infinite poset.

Every finite poset has a topological sort: a total order that respects ⪯.

In the divisibility poset, a∨b=lcm⁡(a,b) and a∧b=gcd⁡(a,b). In (P(S),⊆), join is ∪ and meet is ∩.

6. Lattices

A lattice is a poset in which every pair has both a join and a meet. Every finite lattice is bounded: it has a least element 0 and a greatest element 1.

  • Complement of a: an element b with a∨b=1 and a∧b=0. A lattice is complemented if every element has at least one complement.
  • Distributive: a∧(b∨c)=(a∧b)∨(a∧c) for all a,b,c. In a distributive lattice each element has at most one complement.
  • A Boolean algebra is a complemented distributive lattice, for example (P(S),⊆).

Test for distributivity: a lattice is distributive if and only if it has no sublattice shaped like M3 (the diamond) or N5 (the pentagon). In M3, the element a has two complements b and c, which already breaks distributivity.

Divisor lattice Dn (divisors of n under divisibility, join = lcm, meet = gcd):

  • always distributive;
  • complemented (so Boolean) exactly when n is square-free, such as D30;
  • in D12 the element 2 has no complement, since a complement x would need gcd⁡(2,x)=1 and lcm⁡(2,x)=12.

Every total order is a distributive lattice. A total order with three or more elements is not complemented, since a middle element has no complement.

12346120abc10abc1D12 (divisors of 12)M3, the diamondN5, the pentagon
Hasse diagrams: D12 is distributive but not complemented; M3 and N5 are the two lattices that are not distributive.

Formulas to remember

Inclusion-exclusion (two sets)
∣A∪B∣=∣A∣+∣B∣−∣A∩B∣
Power set
∣P(A)∣=2∣A∣
All relations on n elements
2n2
Reflexive relations
2n(n−1)
Symmetric relations
2n(n+1)/2
Antisymmetric relations
2n⋅3n(n−1)/2
Functions from an m-set to an n-set
nm
Onto functionsFrom an m-set onto an n-set
∑k=0n(−1)k(nk)(n−k)m
Stirling numbers of the second kindS(n,1)=S(n,n)=1
S(n,k)=k S(n−1,k)+S(n−1,k−1)

Common mistakes

  • Treating antisymmetric as the opposite of symmetric; a relation can be both (the identity) or neither.
  • Confusing maximal with greatest: a poset can have many maximal elements and no greatest one.
  • Using nm in the wrong direction: functions from an m-set to an n-set number nm, not mn.
  • Forgetting the inclusion-exclusion correction terms when counting onto functions.
  • Assuming the union of two equivalence relations is an equivalence relation; it may fail transitivity.
  • Calling every Dn a Boolean algebra; it is complemented only when n is square-free.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Counting relations on a 3-element set

numerical

Let A={a,b,c}. Count the reflexive, symmetric, reflexive-and-symmetric, and antisymmetric relations on A.

  1. Step 1: Split the 9 ordered pairs into diagonal and off-diagonal.

    Try it on paper first.

Example 2: Onto functions by inclusion-exclusion

numerical

How many functions from {1,2,3,4} onto {x,y,z} are there?

  1. Step 1: Count all functions first.

    Try it on paper first.

Example 3: Is D12 a complemented lattice?

conceptual

For the divisors of 12 under divisibility, find the join and meet of 4 and 6, and decide whether the lattice is complemented and whether it is distributive.

  1. Step 1: Use lcm for join and gcd for meet.

    Try it on paper first.

Example 4: Equivalence classes of a congruence

numerical

On A={1,2,3,4,5,6} define aRb if a≡b(mod3). List the classes and find ∣R∣.

  1. Step 1: Group the elements by remainder on division by 3.

    Try it on paper first.

Previous year questions

15 official GATE CSE questions on this topic, newest first.

Practise these 15 PYQs →

Topic test

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.