类 KosarajuSharirSCC


  • public class KosarajuSharirSCC
    extends java.lang.Object
    The KosarajuSharirSCC class represents a data type for determining the strong components in a digraph. The id operation determines in which strong component a given vertex lies; the areStronglyConnected operation determines whether two vertices are in the same strong component; and the count operation determines the number of strong components. The component identifier of a component is one of the vertices in the strong component: two vertices have the same component identifier if and only if they are in the same strong component.

    This implementation uses the Kosaraju-Sharir algorithm. The constructor takes time proportional to V + E (in the worst case), where V is the number of vertices and E is the number of edges. Afterwards, the id, count, and areStronglyConnected operations take constant time. For alternate implementations of the same API, see TarjanSCC and GabowSCC.

    For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 构造器概要

      构造器 
      构造器 说明
      KosarajuSharirSCC​(Digraph G)
      Computes the strong components of the digraph G.
    • 方法概要

      修饰符和类型 方法 说明
      int count()
      Returns the number of strong components.
      int id​(int v)
      Returns the component id of the strong component containing vertex v.
      static void main​(java.lang.String[] args)
      Unit tests the KosarajuSharirSCC data type.
      boolean stronglyConnected​(int v, int w)
      Are vertices v and w in the same strong component?
      • 从类继承的方法 java.lang.Object

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

      • KosarajuSharirSCC

        public KosarajuSharirSCC​(Digraph G)
        Computes the strong components of the digraph G.
        参数:
        G - the digraph
    • 方法详细资料

      • count

        public int count()
        Returns the number of strong components.
        返回:
        the number of strong components
      • stronglyConnected

        public boolean stronglyConnected​(int v,
                                         int w)
        Are vertices v and w in the same strong component?
        参数:
        v - one vertex
        w - the other vertex
        返回:
        true if vertices v and w are in the same strong component, and false otherwise
        抛出:
        java.lang.IllegalArgumentException - unless 0 <= v < V
        java.lang.IllegalArgumentException - unless 0 <= w < V
      • id

        public int id​(int v)
        Returns the component id of the strong component containing vertex v.
        参数:
        v - the vertex
        返回:
        the component id of the strong component containing vertex v
        抛出:
        java.lang.IllegalArgumentException - unless 0 <= s < V
      • main

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