Module 1 · 16 min read · Free chapter
Sets, relations, functions, posets and lattices
A relation on n elements is a subset of A × A, so there are 2 to the power n² of them. Reflexive relations number 2 to the power n(n − 1) and symmetric ones 2 to the power n(n + 1)/2. A partial order is reflexive, antisymmetric and transitive, and a lattice needs a join and meet for every pair.
Start from zero: lists, pairs and rules
A school keeps one register for the cricket club and another for the quiz club. Some students are in both, some in only one, and the principal wants to know how many students take part in at least one club. If cricket has 25 names, quiz has 18 and 7 names appear in both, the answer is , because the 7 were counted twice.
Each register is a set: a collection of distinct objects. A pairing such as "student is the captain of team " is a relation, and a rule such as "each student gets exactly one roll number" is a function. When we arrange things by a rule like "is a prerequisite of", we get an order.
This chapter builds these four ideas carefully. They are the vocabulary of the whole of computer science, from database tables to type systems.
Why it matters. A database table is a relation, a hash function is a function, and a task schedule is a partial order. GATE asks you to count relations and functions, test their properties and read Hasse diagrams, all in a few minutes.
Sets and their operations
A set is a collection of distinct elements, written like . Order and repetition do not matter, so is the same set as . The empty set has no elements, and A is a subset of , written , when every element of A is in .
The basic operations are union (in A or ), intersection (in both), difference (in A but not in ) and complement (not in A, inside a fixed universal set ). De Morgan's laws hold here just as in logic: and .
For counting, the key rule is . The power set is the set of all subsets of A, and if then , because each element is either in or out of a subset. The Cartesian product is the set of ordered pairs , and it has elements.
Worked example. Let . has elements: , three singletons, three pairs and A itself. has ordered pairs, which is the starting point for counting relations.
Why it matters. Every relation and function in this chapter is a subset of a Cartesian product. If you can count subsets, you can count relations, and that is a favourite GATE question type.
Relations and their four properties
A relation on a set A is any subset of . We write , or , when a is related to . Since has pairs when , the number of relations on A is . For that is .
Four properties decide what kind of relation we have:
- is reflexive when for every a in A, so every element is related to itself.
- is symmetric when always brings with it.
- is antisymmetric when and can both be in only if .
- is transitive when and in always force .
It helps to picture as an matrix of and . Reflexive means the whole diagonal is 1. Symmetric means the matrix equals its transpose, and antisymmetric means no off-diagonal cell and its mirror are both 1.
Worked example. On the integers, "" is reflexive, antisymmetric and transitive but not symmetric. "a and have the same remainder mod 5" is reflexive, symmetric and transitive. "" is not reflexive, but it is antisymmetric and transitive, because the antisymmetric condition is never triggered.
Why it matters. These four properties decide whether a relation is an equivalence (for grouping) or an order (for ranking). Every later idea in the chapter is built from them.
Counting relations of each kind
Counting relations becomes easy once you split the matrix into two parts. There are diagonal cells (a, a), and the remaining cells form mirror pairs with . Each property puts a rule on one or both parts, and we multiply the free choices.
| Kind of relation | Diagonal choices | Each mirror pair | Count |
|---|---|---|---|
| All relations | 2 each | 4 | |
| Reflexive | 1 each (must be 1) | 4 | |
| Symmetric | 2 each | 2 (both or neither) | |
| Antisymmetric | 2 each | 3 (not both) | |
| Asymmetric | 1 each (must be 0) | 3 | |
| Reflexive and symmetric | 1 each | 2 |
Worked example. Take . There are 3 diagonal cells and 3 mirror pairs. Reflexive relations number , symmetric relations , antisymmetric relations , and relations that are both reflexive and symmetric .
Transitive relations have no simple formula, so exams ask only small cases. On a 2-element set, 13 of the 16 relations are transitive. The three that fail are , and , since each has and without both loops.
Why it matters. This "split the matrix" trick turns a scary counting question into one line of multiplication. It also trains the habit of counting by independent choices, which the combinatorics chapter uses everywhere.
Equivalence relations, partitions and closures
A relation that is reflexive, symmetric and transitive is an equivalence relation. It groups elements that are "the same in some respect". The equivalence class [a] is the set of all elements related to a, and any two classes are either identical or disjoint.
So an equivalence relation cuts the set into non-overlapping, non-empty pieces that cover everything, which is a partition. The reverse is also true: every partition defines the equivalence relation "is in the same piece as". Counting equivalence relations is therefore the same as counting partitions, and these counts are the Bell numbers 1, 2, 5, 15, 52 for , 2, 3, 4, 5.
Worked example. "Same remainder when divided by 3" on the integers gives three classes: , [1] and [2]. On the set the 5 equivalence relations match the 5 partitions: {abc}, {a}{bc}, {b}{ac}, {c}{ab} and .
When a relation lacks a property, the closure is the smallest relation containing it that has the property. The reflexive closure adds all loops (a, a), and the symmetric closure adds every reversed pair, giving . The transitive closure adds every pair joined by a path, and on elements it equals , which Warshall's algorithm finds in steps.
Why it matters. Equivalence classes are behind modular arithmetic, minimising automata and grouping records by key. The transitive closure answers "can I reach from a?", which is the heart of reachability in graphs and of recursive database queries.
Functions and how to count them
A function from A to assigns to every element of A exactly one element of . A is the domain, the codomain, and the set of values actually taken is the range. A function is one-one (injective) when different inputs give different outputs, onto (surjective) when every element of is hit, and a bijection when it is both.
Now let and , so each of the inputs can go to any of outputs, so there are functions in all. For a one-one function the first input has choices, the next , and so on, so there are one-one functions when and none when . When , the one-one functions are exactly the bijections, and there are of them.
Counting onto functions needs inclusion–exclusion. We subtract the functions that miss at least one output, add back those that miss two, and so on. The result is the sum over to of .
Worked example. From a 4-element set to a 3-element set there are functions and no one-one functions. The onto functions number .
A function has an inverse exactly when it is a bijection. Composition keeps the good properties: if and are both one-one, so is , and the same holds for onto.
Why it matters. Hash functions, encodings and encryption are all functions, and whether they are one-one decides whether data can be recovered. Counting functions also shows up in GATE as "how many ways to assign jobs to machines".
Partial orders and Hasse diagrams
A relation that is reflexive, antisymmetric and transitive is a partial order, usually written , and a set with one is a poset. The classic examples are numbers under , subsets under , and positive integers under "divides". It is "partial" because some pairs may be incomparable: neither 2 divides 3 nor 3 divides 2.
If every pair is comparable, the order is a total order or chain, like the integers under . A Hasse diagram draws a poset economically. It leaves out the loops (reflexivity is understood), leaves out every edge implied by transitivity, and puts smaller elements lower so that arrows are not needed.
In a poset, an element is maximal if nothing is above it and greatest if it is above everything. Minimal and least are defined the same way downward. A poset can have several maximal elements but at most one greatest element.
For two elements a and , an upper bound is any element above both, and the least upper bound (lub, or join ) is the smallest such element when it exists. The greatest lower bound (glb, or meet ) is defined the same way downward. In the divisors of 12 under "divides", the join of 4 and 6 is 12 (their lcm) and the meet is 2 (their gcd).
Worked example. Take under "divides". The minimal elements are 2 and 3, and the maximal elements are 4, 6 and 9. There is no least or greatest element, and the pair 4, 9 has no upper bound at all inside this set.
Why it matters. Task scheduling with prerequisites, class inheritance and version histories are all posets. Topological sorting, which every build system and course planner uses, is just extending a partial order to a total order.
Lattices, distributive and complemented lattices
A lattice is a poset in which every pair of elements has both a join and a meet. Subsets of under form a lattice with join and meet . The divisors of under "divides" form a lattice with join lcm and meet gcd. Every finite lattice has a least element 0 and a greatest element 1, so it is bounded.
A lattice is distributive when for all a, , . Two five-element lattices are the standard failures. The diamond has 0, 1 and three incomparable middle elements, and the pentagon has 0, 1, a two-element chain on one side and a single element on the other. A lattice is distributive exactly when it contains neither of these as a sublattice.
In a bounded lattice, is a complement of a when and . A lattice where every element has a complement is complemented. In a distributive lattice an element has at most one complement, while in each middle element has two.
Worked example. In , the complement of 6 is 5, since and . In , the element 2 has no complement, because the only with are 1 and 3, and neither gives lcm 12. In general is always distributive and is complemented exactly when is square-free.
A Boolean algebra is a lattice that is both distributive and complemented. Every finite Boolean algebra has elements and is a copy of the power set of an n-element set, with , and complement. So , with elements, is a Boolean algebra, and this structure is exactly the algebra of logic gates used in Boolean algebra and minimisation.
Why it matters. Lattices appear in data-flow analysis in compilers, in security levels and in the algebra of circuits. GATE asks whether a given Hasse diagram is a lattice, whether it is distributive, and how many complements an element has.
Descriptive lens: how written papers ask this
Written papers for scientist posts and university-level tests ask about this chapter in four ways:
- Prove that a given relation is an equivalence relation and describe its classes.
- Derive a counting formula, such as the number of symmetric or antisymmetric relations, with a clear argument.
- Draw a Hasse diagram and identify maximal, minimal, greatest and least elements and bounds.
- Decide whether a lattice is distributive or complemented, with a reason or a counter-example.
Practice questions (our own, not previous-year questions).
- Prove that the relation " is divisible by 4" on the integers is an equivalence relation, and list its equivalence classes. (8 marks)
- Derive the number of antisymmetric relations on a set of elements, and evaluate it for . (10 marks)
- Draw the Hasse diagram of and decide whether it is a distributive lattice and whether it is complemented. (12 marks)
Answer plan for question 2.
- Explain that a relation on elements is a choice of 0 or 1 for each cell of an matrix.
- Note that the diagonal cells are not restricted by antisymmetry, so they give choices.
- Group the other cells into mirror pairs, each of which may hold neither, only or only .
- Multiply the independent choices to get .
- Evaluate it for as .
Quick revision
- , and .
- A set of elements has relations.
- Reflexive relations number , and symmetric relations number .
- Antisymmetric relations number .
- Equivalence relations match partitions, and their counts are the Bell numbers 1, 2, 5, 15, 52.
- There are functions from elements to elements, and of them are one-one.
- Onto functions from 4 elements to 3 elements number 36 by inclusion–exclusion.
- A partial order is reflexive, antisymmetric and transitive, and a Hasse diagram drops loops and transitive edges.
- A lattice needs a join and a meet for every pair, and and are the non-distributive tests.
- is complemented exactly when is square-free, and a finite Boolean algebra has elements.