- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
Suppose that we are given a directed graph and we want to find out if a vertex $j$ is reachable from another vertex $i$ for all vertex pairs $(i, j)$ in the given graph.
Reachable mean that there is a path from vertex $i$ to $j$.
The reachability matrix is called transitive closure of a graph.I want to write an algorithm that runs in time $O(|V| \cdot |E|)$ and calculates the transitive closure of a directed graph $G=(V,E)$.
I have tried the following:
But the time complexity of the algorithm will be $O(V^2)$, right? (Worried)
What could we change, in order to get the desired time complexity?
Suppose that we are given a directed graph and we want to find out if a vertex $j$ is reachable from another vertex $i$ for all vertex pairs $(i, j)$ in the given graph.
Reachable mean that there is a path from vertex $i$ to $j$.
The reachability matrix is called transitive closure of a graph.I want to write an algorithm that runs in time $O(|V| \cdot |E|)$ and calculates the transitive closure of a directed graph $G=(V,E)$.
I have tried the following:
Code:
Transitive_Closure(G)
compute a topological sorting {v_0, v_1,..., v_(|V|-1)}
for v=1 to |V|
for u=1 to |V|
T(v,u)=0
for v=1 to |V|
C(v,v)
C(i,j)
for each u in Adj[j]
T(i,u)=1
C(i,u)
But the time complexity of the algorithm will be $O(V^2)$, right? (Worried)
What could we change, in order to get the desired time complexity?