IAE Academy

GATE CS

Sets, relations, functions, partial orders and lattices

This topic covers sets, relations, functions, partial orders and lattices, the vocabulary used all through discrete mathematics. Typical questions ask you to count objects (relations with a given property, functions, partitions), to test a relation for its properties, or to decide whether a poset is a lattice and of what kind. The definitions and counting formulas below are stated with their conditions; read each question's own conventions first.

8 previous-year questions · 8 solved · 6 practice questions

Sets and counting with sets

A set is a collection of distinct objects. is the number of elements of a finite set . The power set is the set of all subsets of (including and ). The symmetric difference holds the elements in exactly one of the two sets. The Cartesian product is the set of ordered pairs with , . Complements are taken inside a universe that contains every set in the question: .

SIZE OF THE POWER SET

For a finite set A; each element is either in or out of a subset.

SIZE OF A CARTESIAN PRODUCT

Finite sets. A relation from A to B is any subset of A × B, so there are of them.

INCLUSION-EXCLUSION FOR TWO SETS

Finite sets; this is the basis of Venn-diagram counting.

INCLUSION-EXCLUSION FOR THREE SETS

Finite sets; add singles, subtract pairs, add the triple.

SIZE OF THE SYMMETRIC DIFFERENCE

Finite sets.

Set identities to know

  1. De Morgan: and .

  2. Distributive: and .

  3. .

  4. ; is associative and commutative, and .

  5. if and only if if and only if .

EXAM TIP

In Venn-diagram problems first count the region common to all the sets, then work outwards. At the end check that the regions 'in none', 'in exactly one', 'in exactly two' and 'in all three' add up to .

Countable and uncountable sets

A set is countable if it is finite or can be put in one-to-one correspondence with (countably infinite). Otherwise it is uncountable. Here ; starting from 1 changes nothing about countability. A subset of a countable set is countable. A countable union of countable sets is countable. A finite Cartesian product of countable sets is countable.

Which common sets are countable

Set

Countable?

Reason in one line

,

Yes

List as

Yes

Each rational is a pair of integers; list the pairs in a diagonal order

Finite strings over a finite alphabet

Yes

List by length, then alphabetically

Finite subsets of

Yes

For each , the subsets with largest element are finitely many; a countable union of finite sets

, any interval with

No

Cantor's diagonal argument

No

Cantor's theorem: for every set

All functions

No

Same size as : a subset corresponds to its 0/1 indicator

All functions

No

Contains all functions

All infinite binary strings

No

Same as the functions

EXAM TIP

Countable union and finite product keep countability. The power set of an infinite set, and the set of all functions from an infinite set to a set with at least two elements, are uncountable. is uncountable, since removing a countable set from an uncountable one leaves an uncountable set.

Relations and their properties

A relation on a set is a subset of . Write for . For the relation has an 0/1 matrix with exactly when . The identity relation is . The inverse is .

Properties of a relation R on A

Property

Definition

In the matrix

Reflexive

All diagonal entries are 1

Irreflexive

All diagonal entries are 0

Symmetric

Antisymmetric

No pair with

Asymmetric

Diagonal 0 and no symmetric pair of 1s (irreflexive and antisymmetric)

Transitive

Whenever then

EXAM TIP

Symmetric and antisymmetric are not opposites. The empty relation and the identity relation are both. A relation that is not symmetric need not be antisymmetric. The empty relation is symmetric, antisymmetric, asymmetric, irreflexive and transitive, and is reflexive only when .

ALL RELATIONS ON AN N-ELEMENT SET

Each of the ordered pairs is in or out.

REFLEXIVE RELATIONS

The n diagonal pairs are forced; the other are free. Irreflexive relations have the same count.

NEITHER REFLEXIVE NOR IRREFLEXIVE

For , where no relation is both reflexive and irreflexive: subtract the reflexive and the irreflexive relations from all relations.

SYMMETRIC RELATIONS

Choose freely for each of the diagonal pairs and each of the unordered pairs with .

ANTISYMMETRIC RELATIONS

Diagonal pairs are free (); each unordered pair with has 3 choices: none, only, only.

ASYMMETRIC RELATIONS

Diagonal pairs are excluded; each unordered pair has the same 3 choices. Reflexive and antisymmetric relations have the same count (diagonal forced in instead of out).

REFLEXIVE AND SYMMETRIC RELATIONS

Diagonal forced to 1; each unordered pair with is in or out. Irreflexive and symmetric relations have the same count.

RELATIONS BOTH SYMMETRIC AND ANTISYMMETRIC

Such a relation is a subset of the identity relation, so only the diagonal pairs are free.

EXAM TIP

There is no simple closed form for the number of transitive relations on elements; for the counts are , and small cases are done by listing. The other counts above all come from one idea: separate the diagonal pairs from the unordered off-diagonal pairs, and count the choices for each.

WORKED EXAMPLE

How many antisymmetric relations are there on a set with 4 elements?

Solution
  1. Diagonal pairs: 4, each free, giving choices.

  2. Unordered pairs with : , each with 3 choices (none, one direction, other direction), giving .

  3. Total: .

Answer: 11664

Equivalence relations, closures and composition

An equivalence relation is reflexive, symmetric and transitive. The equivalence class of is . The classes are non-empty, pairwise disjoint and their union is , so they form a partition of . Conversely every partition defines an equivalence relation ( when and lie in the same block). Equivalence relations on and partitions of correspond one to one, and the equivalence relations with exactly classes correspond to the partitions into blocks.

EQUIVALENCE RELATIONS ON N ELEMENTS

(Bell number) counts partitions of an n-element set; (Stirling number of the second kind) counts partitions into exactly non-empty blocks.

RECURRENCES FOR BELL AND STIRLING NUMBERS

With for , and .

PARTITIONS INTO TWO BLOCKS

For : the number of equivalence relations on n elements with exactly two classes.

The reflexive, symmetric and transitive closures of are the smallest relations containing with that property. For relations from to and from to , this page writes composition in the same order as functions: , so is applied first, just as applies first. Some texts write the same relation as ; always read the definition in the question. Powers do not depend on the convention: and .

Closures and composition

Operation

Formula

Matrix view

Reflexive closure

Set the diagonal to 1

Symmetric closure

Transitive closure

for

Warshall's algorithm, or the union of Boolean powers of

Reflexive-transitive closure

Transitive closure with diagonal set to 1

Composition ( first)

Boolean product (AND for multiply, OR for add), in that order

Warshall's algorithm for the transitive closure

  1. Start with the matrix .

  2. For each element in turn, and for every pair : set .

  3. After the last , is the matrix of the transitive closure.

More facts

  1. , and composition of relations is associative.

  2. The intersection of two equivalence relations on is an equivalence relation.

  3. The union of two equivalence relations need not be one: on , the relation joining 1 and 2 and the relation joining 2 and 3 have a union containing and but not .

WORKED EXAMPLE

Find the transitive closure of on .

Solution
  1. : from get ; from get ; from get . So .

  2. : and give ; and give ; and give . So .

  3. contains all 9 ordered pairs.

Answer: (all 9 pairs).

EXAM TIP

For the smallest equivalence relation containing , take the reflexive and symmetric closures (in either order) and the transitive closure last: the transitive closure of a reflexive, symmetric relation stays reflexive and symmetric. Taking the symmetric closure after the transitive one can lose transitivity: is transitive, but its symmetric closure is not, since it lacks .

Functions and counting functions

A function assigns to every exactly one ; is the domain, the codomain and the range. It is injective (one-to-one) if implies ; surjective (onto) if every equals for some ; bijective if both. The composition means apply first: . A function has an inverse function exactly when it is a bijection.

Facts about composition

  1. If is injective then is injective (nothing is said about ).

  2. If is surjective then is surjective (nothing is said about ).

  3. So if is a bijection, is injective and is surjective.

  4. The composition of injective functions is injective; of surjective functions is surjective; of bijections is a bijection.

  5. for bijections .

  6. A function between finite sets of the same size is injective if and only if it is surjective.

ALL FUNCTIONS FROM A TO B

Each element of independently picks an image.

INJECTIVE FUNCTIONS

, , ; when there are none (the product form gives 0).

BIJECTIONS BETWEEN SETS OF EQUAL SIZE

; this is also the number of permutations of an n-set.

SURJECTIVE FUNCTIONS (INCLUSION-EXCLUSION)

, ; zero when .

PARTIAL FUNCTIONS FROM A TO B

, ; each element of maps to one of the elements or is left undefined.

WORKED EXAMPLE

How many surjective functions are there from a 5-element set onto a 3-element set?

Solution
  1. Here , .

  2. Count all functions: .

  3. Subtract functions missing at least one of the 3 targets: .

  4. Add back functions missing two targets (counted twice): .

  5. Functions missing all three targets: none, since .

  6. Total: .

Answer: 150

EXAM TIP

The definition of the domain and codomain matters: the same rule can be onto for one codomain and not onto for another. Also check whether a question counts functions from to or from to ; the formulas for injective and surjective counts use (domain) and (codomain).

Partial orders and Hasse diagrams

A partial order is a relation that is reflexive, antisymmetric and transitive; the pair is a poset. Elements are comparable if or . The poset is a total order (chain) if any two elements are comparable. Element covers if and no element has . A Hasse diagram draws one vertex per element and an edge from up to exactly when covers , leaving out the loops and all edges implied by transitivity. On this page a Hasse diagram is given by its list of covers.

Special elements of a poset (A, ⪯) and a subset S

Term

Meaning

Maximal element

with no such that (there can be several)

Minimal element

with no such that (there can be several)

Greatest element

An element with for all (at most one; it is the only maximal element)

Least element

An element with for all (at most one; it is the only minimal element)

Upper bound of S

An element with for all

Lower bound of S

An element with for all

Least upper bound (join) of S

The least element of the set of upper bounds, if it exists

Greatest lower bound (meet) of S

The greatest element of the set of lower bounds, if it exists

EXAM TIP

A finite non-empty poset always has at least one maximal and one minimal element, and it has a greatest element exactly when it has only one maximal element. In an infinite poset a unique maximal element need not be greatest: in with its usual order plus one extra element comparable to nothing else, is the only maximal element but is not greatest.

SUBSETS OF AN N-SET ORDERED BY INCLUSION

Poset with : is covered by for each .

DIVISIBILITY ON THE DIVISORS OF N

Poset of positive divisors under 'divides' ( distinct primes); join is lcm and meet is gcd.

HASSE DIAGRAM EDGES FOR THE DIVISORS OF N

; is covered by whenever divides . For : .

Chains and antichains

  1. A chain is a subset in which any two elements are comparable; an antichain is a subset in which no two distinct elements are comparable.

  2. In a finite poset, the largest size of an antichain equals the smallest number of chains that together cover the poset.

  3. In a finite poset, the largest number of elements in a chain equals the smallest number of antichains that together cover the poset.

  4. In with , the largest antichain has elements (all subsets of size ).

Every finite poset has a linear extension (a total order that keeps all the given comparisons), found by repeatedly removing a minimal element. This is topological sorting. Partial orders have no simple counting formula: the number of partial orders on a labelled set of 1, 2, 3, 4 elements is 1, 3, 19, 219. The number of total orders on an n-element set is .

Lattices and Boolean algebras

A lattice is a poset in which every pair of elements has a join (least upper bound) and a meet (greatest lower bound). Every finite non-empty lattice has a greatest element and a least element , so it is bounded. In a bounded lattice, is a complement of if and . The lattice is complemented if every element has at least one complement. It is distributive if for all (the dual identity then holds too). A sublattice is a subset closed under the lattice's own join and meet.

Quick tests for common lattices

Lattice

Join / meet

Distributive?

Complemented?

Chain with element

max / min

Yes

Only if it has at most 2 elements

/

Yes

Yes (complement is set complement); a Boolean algebra

Positive divisors of under divisibility

lcm / gcd

Yes

Exactly when is square-free (no repeated prime); then a Boolean algebra

Diamond

Read from the covers below

No

Yes (each atom has two complements)

Pentagon

Read from the covers below

No

Yes ( has two complements, and )

Covers of the diamond and the pentagon

Lattice

Elements

Covers ( means covers )

Diamond

, , , , ,

Pentagon

, , , ,

Facts and tests

  1. A lattice is distributive if and only if it has no sublattice isomorphic to the diamond or the pentagon .

  2. A lattice is modular if implies . It is modular if and only if it has no sublattice isomorphic to . Every distributive lattice is modular; is modular but not distributive.

  3. In a bounded distributive lattice an element has at most one complement.

  4. A Boolean algebra is a complemented distributive lattice. A finite Boolean algebra has elements and is isomorphic to the power set of a -element set.

  5. A finite poset is a lattice when every pair has a join and a meet. Shortcut: a finite poset with a least element in which every pair has a join is a lattice; dually, a finite poset with a greatest element in which every pair has a meet is a lattice.

  6. Lattice laws: idempotent ; commutative; associative; absorption and .

WORKED EXAMPLE

Consider the divisors of under divisibility, and the divisors of under divisibility. Decide for each whether it is a Boolean algebra.

Solution
  1. Divisors of 30: is square-free, with divisors; it is a distributive lattice (lcm and gcd) and every divisor has complement , since and .

  2. So the divisors of 30 form a Boolean algebra, isomorphic to .

  3. Divisors of 12: is not square-free; the divisors are .

  4. Take the element : we need with and . Then must be odd, so has only one factor of 2, which cannot be .

  5. So has no complement; the lattice is distributive but not complemented, hence not a Boolean algebra.

Answer: Divisors of 30: Boolean algebra. Divisors of 12: distributive but not complemented, so not a Boolean algebra.

PREVIOUS-YEAR QUESTIONS

8 questions from the CS papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE CSE 2026 Set 2 · GATE CSE 2025 Set 1 · GATE CSE 2025 Set 2 · GATE CSE 2024 Set 1 · GATE CSE 2024 Set 2 · GATE CSE 2023 · GATE CSE 2020 · GATE CSE 2018

GATE 2025 CS1 Q.17

GATE 2025 · CS1Q.17 · 1 mark · MCQ

is a function from to , is a function from to , and their composition defined as is a mapping from to .

If and are onto (surjective) functions, which ONE of the following is TRUE about the function ?

  1. (A)

    must be an onto (surjective) function.

  2. (B)

    must be a one-to-one (injective) function.

  3. (C)

    must be a bijective function, that is, both one-to-one and onto.

  4. (D)

    is not required to be a one-to-one or onto function.

Answer and solution
See the question in the paper
GATE 2025 CS1 Q.17: answer and solution

GATE 2025 CS2 Q.42

GATE 2025 · CS2Q.42 · 2 marks · MSQ

Let be the set of all functions from to . Define the binary relation on as follows:

if and only if , where .

Which of the following statement(s) is/are TRUE?

  1. (A)

    is a symmetric relation

  2. (B)

    is a partial order

  3. (C)

    is a lattice

  4. (D)

    is an equivalence relation

Answer and solution
See the question in the paper
GATE 2025 CS2 Q.42: answer and solution

GATE 2023 CS Q.49

GATE 2023 · CSQ.49 · 2 marks · MSQ

Let be an onto (or surjective) function, where and are nonempty sets. Define an equivalence relation on the set as

where . Let be the set of all the equivalence classes under . Define a new mapping as

Which of the following statements is/are TRUE?

  1. (A)

    is NOT well-defined.

  2. (B)

    is an onto (or surjective) function.

  3. (C)

    is a one-to-one (or injective) function.

  4. (D)

    is a bijective function.

Answer and solution
See the question in the paper
GATE 2023 CS Q.49: answer and solution

GATE 2018 CS Q.27

GATE 2018 · CSQ.27 · 2 marks · MCQ

Let be the set of natural numbers. Consider the following sets.

: Set of Rational numbers (positive and negative)
: Set of functions from to
: Set of functions from to
: Set of finite subsets of .

Which of the sets above are countable?

  1. (A)

    and only

  2. (B)

    and only

  3. (C)

    and only

  4. (D)

    , and only

Answer and solution
See the question in the paper
GATE 2018 CS Q.27: answer and solution

PRACTICE

6 questions to test yourself

PRACTICE 12 marks · NAT

How many asymmetric relations are there on a set with exactly 4 elements? (A relation on is asymmetric if implies for all , including .)

Answer and solution

Answer:

  1. Asymmetric forces the diagonal pairs out, so no diagonal pair is in .

  2. There are unordered pairs with .

  3. Each has 3 choices: neither, only, or only.

  4. Total .

PRACTICE 22 marks · MCQ

Let be the set of positive divisors of ordered by divisibility. Which statement is true?

  1. (A)

    is a lattice, is distributive, and is complemented

  2. (B)

    is a lattice, is distributive, but is not complemented

  3. (C)

    is a lattice but is not distributive

  4. (D)

    is not a lattice

Answer and solution

Answer: (B)

  1. Any two divisors have an lcm (join) and a gcd (meet) among the divisors, so is a lattice, and it is distributive because gcd and lcm distribute over each other.

  2. is not square-free, so is not complemented.

  3. Direct check: for we need with and ; the second needs , which contradicts the first.

  4. So the answer is B.

PRACTICE 32 marks · NAT

How many surjective functions are there from a set with 4 elements onto a set with 3 elements?

Answer and solution

Answer:

  1. Use inclusion-exclusion with , : .

  2. .

  3. Check: .

PRACTICE 41 mark · NAT

How many equivalence relations on the set have exactly two equivalence classes?

Answer and solution

Answer:

  1. Equivalence relations with exactly two classes correspond to partitions into two non-empty blocks.

  2. The count is .

  3. Check by block sizes: one block of size 1 and one of size 3 gives 4 partitions; two blocks of size 2 gives ; total .

PRACTICE 51 mark · MCQ

Consider the poset of all subsets of ordered by inclusion. How many edges does its Hasse diagram have?

  1. (A)

    9

  2. (B)

    12

  3. (C)

    16

  4. (D)

    27

Answer and solution

Answer: (B)

  1. An edge joins to for (a cover).

  2. Total edges .

  3. Check by levels: sizes 0 to 1 give 3 edges, 1 to 2 give 6 edges, 2 to 3 give 3 edges, total 12.

PRACTICE 61 mark · MSQ

Let be the relation on the set of integers defined by if and only if . Which of the following properties does have?

  1. (A)

    Reflexive

  2. (B)

    Symmetric

  3. (C)

    Antisymmetric

  4. (D)

    Transitive

Answer and solution

Answer: (A), (B)

  1. , so is reflexive.

  2. , so is symmetric.

  3. and but , so not antisymmetric.

  4. and but , so not transitive.

  5. Correct options: A and B.

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE CS

Sets, relations, functions, partial orders and lattices

Preparing in Kolkata? IAE Academy's course for GATE CSE.