VOOZH about

URL: https://www.geeksforgeeks.org/dsa/transitive-relation-on-a-set/

⇱ Check Transitive Relation on a Set - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check Transitive Relation on a Set

Last Updated : 23 Jul, 2025

A relation is a subset of the cartesian product of a set with another set. A relation contains ordered pairs of elements of the set it is defined on. To learn more about relations refer to the article on "Relation and their types".

What is a Transitive Relation?

A relation R on a set A is called transitive relation if and only if

∀ a, b, c ∈ A, if (a, b) ∈ R and (b, c) ∈ R then (a, c) ∈ R, 
where R is a subset of (A x A), i.e. the cartesian product of set A with itself.

This means if an ordered pair of elements "a" to "b" (aRb) and "b" to "c" (bRc) is present in relation R, then an ordered pair of elements "a" to "c" (aRC) should also be present in the relation R. If any such aRc is not present for any aRb & bRc in R then R is not a transitive relation.

Example:

Consider set A = {a, b, c}

R = {(a, b), (b, c), (a, c)} is transitive relation but
R = {(a, b), (b, c)} is not transitive relation

Properties of Transitive Relation

  1. Empty relation on any set is always transitive.
  2. Universal relation on any set is always transitive.

How to verify a Transitive Relation?

To verify transitive relation:

  • Firstly, find the tuples of form aRb & bRc in the relation.
  • For every such pair check if aRc is also present in R.
  • If any of the tuples does not exist then the relation is not transitive else it is transitive.

Follow the below illustration for a better understanding

Illustration:

Consider set R = {(1, 2), (1, 3), (2, 3), (3, 4)}

For the pairs (1, 2) and (2, 3):
    => The relation (1, 3) exists
    => This satisfies the condition.

For the pairs (1, 3) and (3, 4):
    => The relation (1, 4) does not exist
    => This does not satisfy the condition.

So the relation is not transitive.

Below is the code implementation of the idea:


Output
Not a Transitive Relation

Time Complexity: O(N * K * log N) where N is the number of tuples in relation and K is the maximum number of tuples (a, b) for which a are same
Auxiliary Space: O(N)

Comment
Article Tags:
Article Tags: