Table of Contents Previous Section Next Section

10.5 Transitive Closure

In many applications we wish to determine if any two vertices in a graph are connected. This is usually done by finding the transitive closure of a graph. Formally, if G = (V, E) is a graph, then the transitive closure of G is defined as the graph G* = (V, E*), where E* = {(vi, vj)| there is a path from vi to vj in G}. We compute the transitive closure of a graph by computing the connectivity matrix A*. The connectivity matrix of G is a matrix graphics/10fig36.gif such that graphics/01icon05.gif if there is a path from vi to vj or i = j, and graphics/01icon04.gif otherwise.

To compute A* we assign a weight of 1 to each edge of E and use any of the all-pairs shortest paths algorithms on this weighted graph. Matrix A* can be obtained from matrix D, where D is the solution to the all-pairs shortest paths problem, as follows:

graphics/10fig37.gif


Another method for computing A* is to use Floyd's algorithm on the adjacency matrix of G, replacing the min and + operations in line 7 of Algorithm 10.3 by logical or and logical and operations. In this case, we initially set ai,j = 1 if i = j or (vi, vj) E, and ai,j = 0 otherwise. Matrix A* is obtained by setting graphics/01icon04.gif if di,j = 0 and graphics/01icon05.gif otherwise. The complexity of computing the transitive closure is Q(n3).

    Table of Contents Previous Section Next Section