1
$\begingroup$

I'm trying to solve a graph problem ( it's not for homework, just to practise my skills ).

A dag $G(V,E)$ is given, where $V$ is the set of vertices and $E$ the edges. The graph is represented as an adjacency list, so $A_i$ is a set containing all the connections of $i$.

My task is to find which vertices are reachable from each vertex $v\in V$.

The solution I use has a complexity of $O(V^3)$, with transitive closure, but i read that in a blog it can be faster, although it didn't reveal how. Could anyone tell me an other way ( with better complexity ) to solve the transitive closure problem in a dag? Thanks in advance.

$\endgroup$
8
  • $\begingroup$ What is $f(\cdot)$? $\endgroup$
    – Dimitris
    Dec 6, 2012 at 18:18
  • $\begingroup$ @JɛffE Sorry I edited it. I misunderstood what the blog said. $\endgroup$ Dec 6, 2012 at 18:45
  • 5
    $\begingroup$ i think this is for cs@stackexchange $\endgroup$ Dec 6, 2012 at 19:28
  • 1
    $\begingroup$ Check this out: sciencedirect.com/science/article/pii/0304397588900321 $\endgroup$
    – George
    Dec 6, 2012 at 20:57
  • $\begingroup$ @Kaveh isn't the problem exactly transitive closure here? $\endgroup$ Dec 13, 2012 at 8:26

1 Answer 1

2
$\begingroup$

Here is an $O(VE)$ algorithm, which is substantially better than $O(V^3)$ if the graph is sparse. First do a topological sort, in time $O(V+E)$. Now work your way backwards, storing which vertices are reachable. At a vertex of outdegree $d$, this requires $O(dV)$ work, so in total you get $O(VE)$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.