ConstReturns 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.
the graph
the bridges, articulation points and biconnected components
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.
the graph
the connected components
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.
the graph
the SCCs
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.
the graph
the strong bridges and strong articulation points
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.
the graph
the weakly connected components
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.
sccsOfandstrongConnectivityOffollow them in their direction.wccsOf,ccsOfandbiconnectivityOfread the graph as undirected: an edge connects its source and target whether or not the reverse edge exists, and the edgesa -> bandb -> acount 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.