Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have constructed a viable solution to this question. I base my solution on a modification of the <a href="http://en.wikipedia.org/wiki/Topological_sort" rel="nofollow noreferrer">topological sorting</a> algorithm. The algorithm below calculates only the in-degree in the transitive closure. The out-degree can be computed in the same fashion with edges reversed and the two counts for each vertex summed to determine the final "reachability count".</p> <pre><code>for each vertex V inCount[V] = inDegree(V) // inDegree() is O(1) if inCount[V] == 0 pending.addTail(V) while pending not empty process(pending.removeHead()) function process(V) for each edge (V, V2) predecessors[V2].add(predecessors[V]) // probably O(|predecessors[V]|) predecessors[V2].add(V) inCount[V2] -= 1 if inCount[V2] == 0 pending.add(V2) count[V] = sizeof(predecessors[V]) // store final answer for V predecessors[V] = EMPTY // save some memory </code></pre> <p>Assuming that the set operations are O(1), this algorithm runs in O(|V| + |E|). It is more likely, however, that the set union operation <code>predecessors[V2].add(predecessors[V])</code> makes it somewhat worse. The additional steps required by the set unions depends on the shape of the DAG. I believe the worst case is O(|V|^2 + |E|). In my tests this algorithm has shown better performance than any other I have tried so far.</p> <p>Furthermore, by disposing of predecessor sets for fully processed vertices, this algorithm will typically use less memory than most alternatives. It is true, however, that the worst case memory consumption of the above algorithm matches that of constructing the transitive closure, but that will not be true for most DAGs.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload