类 TransitiveClosure


  • public class TransitiveClosure
    extends java.lang.Object
    The TransitiveClosure class represents a data type for computing the transitive closure of a digraph.

    This implementation runs depth-first search from each vertex. The constructor takes time proportional to V(V + E) (in the worst case) and uses space proportional to V2, where V is the number of vertices and E is the number of edges.

    For large digraphs, you may want to consider a more sophisticated algorithm. Nuutila proposes two algorithm for the problem (based on strong components and an interval representation) that runs in E + V time on typical digraphs. For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 构造器概要

      构造器 
      构造器 说明
      TransitiveClosure​(Digraph G)
      Computes the transitive closure of the digraph G.
    • 方法概要

      修饰符和类型 方法 说明
      static void main​(java.lang.String[] args)
      Unit tests the TransitiveClosure data type.
      boolean reachable​(int v, int w)
      Is there a directed path from vertex v to vertex w in the digraph?
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • TransitiveClosure

        public TransitiveClosure​(Digraph G)
        Computes the transitive closure of the digraph G.
        参数:
        G - the digraph
    • 方法详细资料

      • reachable

        public boolean reachable​(int v,
                                 int w)
        Is there a directed path from vertex v to vertex w in the digraph?
        参数:
        v - the source vertex
        w - the target vertex
        返回:
        true if there is a directed path from v to w, false otherwise
        抛出:
        java.lang.IllegalArgumentException - unless 0 <= v < V
        java.lang.IllegalArgumentException - unless 0 <= w < V
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the TransitiveClosure data type.
        参数:
        args - the command-line arguments