The time complexity of computing the transitive closure of a binary relation on a set of n elements is known to be: A. O(n) B. O(n log n) C. O(n^(3/2)) D. O(n^3)
GATE 2005 · Discrete Mathematics · Relations · medium
Answer: D. O(n^3)
- Represent the relation as an n x n boolean matrix: Initialize the n x n adjacency matrix of the relation in O(n^2) time.
- Apply Floyd-Warshall to compute transitive closure: Three nested loops each running n times gives O(n^3) total operations.