The time complexity of computing the transitive closure of a binary relation on a set of elements is known to be:
View worked solution
Answer: D
A binary relation on a set of elements can be represented as a directed graph with vertices, where an edge exists from vertex to vertex if and only if is related to .
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 times:
This results in a time complexity of , which is .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])
Therefore, the time complexity of computing the transitive closure is known to be .
Free practice · Your answers on this page are not saved.
