Graphity for TypeScript 3.0.0
    Preparing search index...

    Variable ComponentsConst

    Components: {
        biconnectivityOf(graph: BiAdjacentGraph): Biconnectivity;
        ccsOf(graph: Graph): NodePartition;
        sccsOf(graph: Graph): Sccs;
        strongConnectivityOf(graph: BiAdjacentGraph): StrongConnectivity;
        wccsOf(graph: Graph): NodePartition;
    } = ...

    The algorithms for the components of a graph, and for the edges and nodes whose removal splits them.

    Components.sccsOf returns the SCCs (strongly connected components), and Components.wccsOf the weakly connected components. Components.ccsOf returns the weakly connected components under another name: the connected components of the graph read as undirected. Components.biconnectivityOf returns the bridges, articulation points and biconnected components. Bridges and articulation points are the edges and nodes whose removal splits a connected component. Components.strongConnectivityOf returns the strong bridges and strong articulation points, which split an SCC.

    A graph is always directed, and each method says how it reads the edges. sccsOf and strongConnectivityOf follow them in their direction. wccsOf, ccsOf and biconnectivityOf read the graph as undirected: an edge connects its source and target whether or not the reverse edge exists, and the edges a -> b and b -> a count as one undirected edge, not two. An undirected graph can therefore be stored with one edge per pair of neighbors or with both directions, and these methods read it the same way. For the bridges this matters: read as two edges, the two directions would form a cycle, and no edge stored in both directions could be a bridge.

    Type Declaration

    • biconnectivityOf: function
      • Returns the bridges, articulation points and biconnected components of graph, read as undirected.

        All three come from one depth-first search, so there is no cheaper method for one of them alone; Biconnectivity describes them. The search follows the edges of every node in both directions, so it takes a BiAdjacentGraph. For a plain Graph, call Components.biconnectivityOf(BiAdjacentGraph.of(graph)). Uses the algorithm of Hopcroft and Tarjan, without recursion.

        Time: O(nodeCount + edgeCount). Memory: up to 8 x edgeCount + 20 x nodeCount bytes for the result; while it runs, 8 x edgeCount + 63 x nodeCount bytes more.

        Parameters

        Returns Biconnectivity

        the bridges, articulation points and biconnected components

    • ccsOf: function
      • Returns the connected components of graph read as undirected. Equivalent to wccsOf(graph).

        The two names let a call say which reading of the graph it means.

        Time: O((nodeCount + edgeCount) x alpha(nodeCount)), as for Components.wccsOf. Memory: up to 12 x nodeCount bytes for the result; while it runs, 9 x nodeCount bytes more.

        Parameters

        Returns NodePartition

        the connected components

    • sccsOf: function
      • Returns the SCCs of graph. Uses Tarjan's algorithm, without recursion.

        Every node is in exactly one SCC; a node that lies on no cycle is an SCC of its own. SCC IDs are in reverse topological order: every edge between two SCCs goes from the higher SCC ID to the lower one, so SCC 0 has no edges to other SCCs. The nodes of each SCC are in ascending order. Here, dependencies are the dependencies between the packages of a program, and names holds the names of the packages. The example groups the packages by SCC, in the order of the SCC IDs. In this order, each package comes after the packages it uses, and the packages that use each other come together:

        // The SCCs in reverse topological order, each as the names of its packages.
        const sccs = Components.sccsOf(dependencies);
        const buildOrder: string[][] = [];
        for (let scc = 0; scc < sccs.sccCount; scc++) {
        buildOrder.push(Array.from(sccs.nodesOf(scc), (node) => names[node]));
        }
        // buildOrder: [[util], [cli], [json], [model, storage], [service], [ui], [app]]

        Time: O(nodeCount + edgeCount), plus sorting the nodes of each SCC: up to O(nodeCount log nodeCount) when one SCC holds most of the nodes. Memory: up to 12 x nodeCount bytes for the result; while it runs, 24 x nodeCount bytes more.

        Parameters

        Returns Sccs

        the SCCs

        Error if graph has more than 2^30 - 5 nodes

    • strongConnectivityOf: function
      • Returns the strong bridges and strong articulation points of graph. These are the edges and nodes whose removal splits an SCC.

        The edges are followed in their direction, as by Components.sccsOf; StrongConnectivity describes the results. The computation also follows them against their direction, so it takes a BiAdjacentGraph. For a plain Graph, call Components.strongConnectivityOf(BiAdjacentGraph.of(graph)). Uses the algorithm of Italiano, Laura and Santaroni, which finds both from the Dominators within each SCC, without recursion.

        Time: O((nodeCount + edgeCount) log nodeCount). Memory: up to 28 x nodeCount bytes for the result; while it runs, about 80 x nodeCount bytes more.

        Parameters

        Returns StrongConnectivity

        the strong bridges and strong articulation points

        Error if graph has more than 2^30 - 6 nodes

    • wccsOf: function
      • Returns the weakly connected components of graph. These are the components of the graph read as undirected.

        Every node is in exactly one component. Each component is a group of the result. The groups are in the order of their smallest nodes: group 0 holds node 0, group 1 the smallest node not in group 0, and so on. Uses union-find, whose cost grows with alpha(nodeCount). The inverse Ackermann function alpha is below 5 for any graph.

        Time: O((nodeCount + edgeCount) x alpha(nodeCount)). Memory: up to 12 x nodeCount bytes for the result; while it runs, 9 x nodeCount bytes more.

        Parameters

        Returns NodePartition

        the weakly connected components