Function articulation_points

Source
pub fn articulation_points<G>(g: G) -> HashSet<G::NodeId>
Expand description

[Generic] Find articulation points in a graph using Tarjan’s algorithm.

Compute the articulation points of a graph (Nodes, which would increase the number of connected components in the graph.

§Arguments

  • graph: A directed graph

§Returns

  • HashSet: HashSet of the node ids which correspond to the articulation points of the graph.

§Examples

use petgraph::{
    algo::articulation_points,
    graph::{NodeIndex, UnGraph},
    algo::articulation_points::articulation_points,
};

let mut gr = UnGraph::<&str, ()>::new_undirected();
let a = gr.add_node("A");
let b = gr.add_node("B");
let c = gr.add_node("C");

gr.add_edge(a, b, ());
gr.add_edge(b, c, ());

let articulation_points: Vec<&str> = articulation_points(&gr)
    .into_iter()
    .map(|node_idx| gr[node_idx])
    .collect();

// Articulation Points: ["B"]
println!("Articulation Points: {:?}", articulation_points);