Function rustworkx_core::connectivity::number_connected_components
source · pub fn number_connected_components<G>(graph: G) -> usizewhere
G: GraphProp + IntoNeighborsDirected + Visitable + IntoNodeIdentifiers,
G::NodeId: Eq + Hash,Expand description
Given a graph, return the number of connected components of the graph.
Arguments:
graph- The graph object to run the algorithm on
Example
use rustworkx_core::petgraph::{Graph, Undirected};
use rustworkx_core::connectivity::number_connected_components;
let graph = Graph::<(), (), Undirected>::from_edges([(0, 1), (1, 2), (3, 4)]);
assert_eq!(number_connected_components(&graph), 2);