edited by
4,254 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)$
edited by

3 Answers

Best answer
17 votes
17 votes

$\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
2 votes
2 votes
Option c is the answer
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

9 votes
9 votes
5 answers
1
sh!va asked May 7, 2017
8,001 views
The number of swappings needed to sort the numbers $8 , 22, 7, 9, 31, 5, 13$ in ascending order using bubble sort is$11$$12$$13$$10$
10 votes
10 votes
5 answers
2
sh!va asked May 7, 2017
4,913 views
Which one of the following in-place sorting algorithms needs the minimum number of swaps?Insertion SortQuick SortHeap SortSelection Sort
5 votes
5 votes
3 answers
3
sh!va asked May 7, 2017
4,433 views
Which of the following algorithms solves the all pair shortest path problem?Prim's algorithmDijkstra's algorithmBellman ford algorithmFloyd warshalls algorithm
29 votes
29 votes
7 answers
4