Function number_connected_components

Source
pub fn number_connected_components<G>(graph: G) -> usize
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);