Introduction
A relation records which elements of one set are associated with which elements of another: " divides ", " is a prerequisite of ", "page links to page ". Formally, a (binary) relation from a set to a set is any subset ; we write or . A relation on is a subset of .
Relations generalise functions, define orderings (partial orders) and groupings (equivalence relations), and appear throughout computer science: reachability in graphs, functional dependencies in databases, and tables in the relational model (which use -ary relations).
Prerequisites
- Sets: Cartesian products, subsets, partitions, power sets.
Core concepts
Representations
For a relation on a finite set :
- Set of pairs: .
- Zero-one matrix : if , else 0.
- Directed graph (digraph): a vertex per element, an arc per pair; a pair is a loop.
Since , there are relations on an -element set.
Properties of a relation on
| Property | Definition | Matrix view | Digraph view |
|---|---|---|---|
| Reflexive | all diagonal entries 1 | loop at every vertex | |
| Irreflexive | all diagonal entries 0 | no loops | |
| Symmetric | every arc has its reverse | ||
| Antisymmetric | only if | no pair of opposite arcs between distinct vertices | |
| Asymmetric | antisymmetric and zero diagonal | antisymmetric and no loops | |
| Transitive | (Boolean product) | every directed walk of length 2 has a shortcut arc |
Important distinctions:
- Not reflexive is not the same as irreflexive. on is neither.
- Symmetric and antisymmetric are not opposites. The empty relation and the identity relation are both. is neither.
- Asymmetric = antisymmetric + irreflexive. Asymmetric implies irreflexive (take ).
- The empty relation on a non-empty set is irreflexive, symmetric, antisymmetric, asymmetric and transitive, but not reflexive.

Counting relations with a property
For a set with elements there are diagonal pairs and unordered pairs with . Each count comes from deciding diagonal pairs and off-diagonal pairs independently.
| Relations on an -set that are | Count | |
|---|---|---|
| Any | 512 | |
| Reflexive | 64 | |
| Irreflexive | 64 | |
| Symmetric | 64 | |
| Reflexive and symmetric | 8 | |
| Antisymmetric | 216 | |
| Asymmetric | 27 | |
| Reflexive and antisymmetric | 27 | |
| Equivalence relations | Bell number | 5 |
Reasoning for antisymmetric: each diagonal pair is free (2 ways); for each unordered off-diagonal pair , allow neither arc, only , or only (3 ways). There is no simple closed formula for transitive relations; for there are 2, 13, 171, 3994.
Operations on relations
- Inverse: ; .
- Complement: .
- Composition: for and ,
and , the Boolean matrix product (OR of ANDs). Note the order: applies first, as with functions.
- Powers: , . if and only if there is a directed walk of length exactly from to in the digraph.
- is transitive if and only if (equivalently for all ).
Closures
The closure of with respect to a property is the smallest relation that contains and has the property.
| Closure | Formula |
|---|---|
| Reflexive | , where |
| Symmetric | |
| Transitive | for |
| Reflexive-transitive |
The transitive closure is reachability by a nonempty directed walk. For distinct endpoints, remove repeated segments to obtain a simple path of length at most ; for equal endpoints, take a shortest nonempty return cycle of length at most . Thus the union stops at . Warshall's algorithm computes it in time. Matrix indices below are 1-based, from 1 through n. On the unit-cost Boolean-matrix model, best, average and worst time are all , since all three loops run fully. A separate W needs auxiliary space; updating M in place uses additional scalar space:
WARSHALL(M, n) // M is the n x n zero-one matrix of R
W <- M
for k <- 1 to n
for i <- 1 to n
for j <- 1 to n
W[i][j] <- W[i][j] OR (W[i][k] AND W[k][j])
return W // matrix of the transitive closureAfter iteration , exactly when there is a nonempty directed walk (including a return cycle when the endpoints coincide) from to whose intermediate vertices all lie in . It is the Boolean version of Floyd-Warshall.
Caution: the symmetric closure of a transitive relation need not be transitive, and the transitive closure of a symmetric relation is symmetric. To get the smallest equivalence relation containing , take the reflexive, symmetric and then transitive closure, in that order (transitive last).
Equivalence relations and partitions
A relation is an equivalence relation if it is reflexive, symmetric and transitive. The equivalence class of is .
Key facts:
- Any two classes are either identical or disjoint: if and only if .
- The distinct classes form a partition of ; conversely every partition of defines an equivalence relation ("in the same block"). This bijection is why the number of equivalence relations on an -set equals the number of partitions, the Bell number : .
- An equivalence relation whose partition has blocks of sizes contains exactly ordered pairs.
Examples: congruence modulo on ( if ) has the classes . "Same length" on strings is an equivalence relation. "Is a friend of" is usually not (not transitive).

Partial orders (preview)
A relation that is reflexive, antisymmetric and transitive is a partial order (for example on , on , "divides" on ). These are treated in Partial Orders and Lattices.
Worked examples
Example 1: classify relations
On :
| Relation | Refl. | Irrefl. | Symm. | Antisymm. | Trans. |
|---|---|---|---|---|---|
| Yes | No | Yes | No | Yes | |
| No | Yes | No | Yes | Yes | |
| No | Yes | Yes | No | No | |
| No | No | Yes | Yes | Yes |
fails transitivity because but . is an equivalence relation with classes and , and pairs, as listed.
Example 2: transitive closure
on . , , . So
6 pairs: the strict order on .
Example 3: counting
How many relations on a 4-element set are both reflexive and symmetric? The diagonal is forced; each of the unordered pairs is in or out (both directions together): . How many are symmetric and antisymmetric? Off-diagonal pairs must all be absent; the diagonal is free: .
Example 4: equivalence relations with a given class structure
How many equivalence relations on have exactly two classes? This is the number of ways to split a 4-set into 2 non-empty blocks, the Stirling number : four splits of type 3+1 and three of type 2+2. Over all numbers of classes, .
Important properties and observations
- Intersection of two equivalence relations is an equivalence relation; their union need not be (transitivity fails). Example on : classes and ; the union contains but not .
- Unions preserve reflexivity, irreflexivity and symmetry, but not antisymmetry, asymmetry or transitivity. Intersections preserve reflexivity, irreflexivity, symmetry, antisymmetry, asymmetry and transitivity (irreflexivity, antisymmetry and asymmetry pass to every subset; reflexivity, symmetry and transitivity survive because each pair the definition requires is in both relations, so it is in the intersection: if then and , and likewise if then is in both).
- The inverse preserves all six of those properties. The complement preserves symmetry only, and it swaps reflexivity with irreflexivity. Composition of two relations preserves reflexivity only.
| Operation | Preserves | Does not preserve |
|---|---|---|
| Union | reflexive, irreflexive, symmetric | antisymmetric, asymmetric, transitive |
| Intersection | all six | none |
| Inverse | all six | none |
| Complement | symmetric (and swaps reflexive with irreflexive) | reflexive, irreflexive, antisymmetric, asymmetric, transitive |
| Composition | reflexive | irreflexive, symmetric, antisymmetric, asymmetric, transitive |
- is symmetric if and only if ; antisymmetric if and only if .
- A relation that is symmetric, transitive and "serial" (every element related to something) is reflexive; without the serial condition the classic false proof of "symmetric and transitive implies reflexive" fails, as shows.
GATE examination perspective
- Property checks. Expect a relation given by pairs or by a rule on integers (for example if is even, or if ); test each property and look for a single counterexample.
- Counting relations. The counting-relations table covers the common counts. Derive them from the diagonal/off-diagonal split instead of memorising.
- Equivalence classes and partitions. Bell numbers for the total; Stirling numbers of the second kind for a fixed number of classes.
- Closures. Transitive closure equals reachability; Warshall's algorithm is .
- Trap: "not reflexive" versus "irreflexive"; "antisymmetric" versus "not symmetric".
- Trap: on is reflexive and symmetric but not transitive (, , but ).
Summary
Sources
- K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., McGraw-Hill, 2012: Sections 9.1 (Relations and Their Properties), 9.3 (Representing Relations), 9.4 (Closures of Relations) and 9.5 (Equivalence Relations).