Skip to main content

is_strongly_connected

Function is_strongly_connected 

Source
pub fn is_strongly_connected(graph: &Graph) -> bool
Expand description

Returns whether graph is strongly connected: every node reaches every other along the edges.

Answers without the partition of components::sccs_of. Uses Tarjan’s algorithm, without recursion. It starts from node 0 and stops as soon as an SCC without node 0 is complete. Where the SCCs are already computed, Sccs::is_strongly_connected answers in O(1). The empty graph is strongly connected, and so is a single node. For the undirected reading, see is_weakly_connected.

Time: O(node_count + edge_count), stopping at the first SCC without node 0. Memory: 8 x node_count bytes while it runs, and up to 8 x node_count bytes for the stack, which grows with the deepest path.

§Panics

With an invalid argument message if a depth-first path is longer than 2^30 - 5 nodes.