in Algorithms edited by
4,216 views
14 votes
14 votes
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\log n)$

b. $O\left( n^{3/2}\right)$

c. $O( n^3 )$

d. $O(n)$
in Algorithms edited by
by
4.2k views

1 comment

Using  Warshall's Algorithm: Transitive Closure we can do it in O(n3) bit  operations

Hence C is the correct answer...

7
7

3 Answers

17 votes
17 votes
Best answer

$\begin{bmatrix}
0 & 1 & 1 & 0 & 0 & 1 \\
1 & 0 & 1 & 1 & 0 & 0 \\
0 & 1 & 0 & 1 & 1 & 1 \\
1 & 1 & 1 & 0 & 1 & 0 \\
0 & 1 & 0 & 1 & 0 & 1 \\
1 & 1 & 0 & 1 & 1 & 0 \\
\end{bmatrix}$

If above is a binary relation in it's matrix representation.

Then the following is the $O(V^3)$ Warshall's Algorithm to find the Transitive closure of the underlying graph or binary relation.

for(int via = 0; via < V; via++) {
  for(int start = 0; start < V; start++) {
    for(int end = 0; end < V; end++) {
      matrix[start][end] = matrix[start][end] | ( matrix[start][via] & matrix[via][end] );
    }
  }
}
selected by
by
2 votes
2 votes
Option c is the answer
by
0 votes
0 votes
The time complexity of computing the transitive closure is:

3 nested for loops so time complexity is n^3.

Option C
Answer:

Related questions