![]() |
VOOZH | about |
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".
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
To verify transitive relation:
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:
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)