Skip to content
Official PYQ · 2005

GATE CS 2005 Q7 — Sets, Relations and Functions

Explain with AI

The time complexity of computing the transitive closure of a binary relation on a set of nn elements is known to be:

Choose one option
View worked solution

Answer: D

A binary relation on a set of nn elements can be represented as a directed graph with nn vertices, where an edge exists from vertex uu to vertex vv if and only if uu is related to vv.

Computing the transitive closure of this relation is equivalent to finding the all-pairs reachability in the corresponding directed graph.

  • Warshall's Algorithm: The standard and most widely used algorithm to compute the transitive closure of a relation is Warshall's algorithm.
  • Complexity: Warshall's algorithm uses dynamic programming with three nested loops, each running nn times:
    for k = 1 to n:
        for i = 1 to n:
            for j = 1 to n:
                reach[i][j] = reach[i][j] or (reach[i][k] and reach[k][j])
    This results in a time complexity of Θ(n3)\Theta(n^3), which is O(n3)O(n^3).

Therefore, the time complexity of computing the transitive closure is known to be O(n3)O(n^3).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Sets, Relations and Functions questions