3.5 Find the edges and nodes whose removal splits a strongly connected component
You find the strong bridges and strong articulation points of a graph, without which a strongly connected component splits into several.
Problem
Section titled “Problem”You have a group of nodes in which every node reaches every other, and you want to know which edges and nodes keep it that way. If no further node can join the group, it is an SCC (strongly connected component). Some edges and nodes are indispensable: without one of them, some nodes of the SCC no longer reach the others, and the SCC splits into several. An indispensable edge is called a strong bridge. An indispensable node is called a strong articulation point. You need them wherever an SCC should stay one:
- a network of one-way connections: they are its single points of failure;
- a loop of a control-flow graph: they are the edges and blocks without which the blocks of the loop no longer reach each other;
- a group of modules that depend on each other in a cycle: they are the dependencies and modules whose removal splits the group.
Example
Section titled “Example”The method loadloadloadLoad of a small program reads the
lines of a file and parses each line that is not blank into a note:
List<Note> load(Path file) { List<String> lines = read(file); // entry List<Note> notes = new ArrayList<>(); for (int i = 0; i < lines.size(); i++) { // header: i < lines.size() String line = lines.get(i); // body if (!line.isBlank()) { notes.add(parse(line)); // then } } // next: i++ return notes; // exit}fn load(file: &Path) -> Vec<Note> { let lines = read(file); // entry let mut notes = Vec::new(); let mut i = 0; while i < lines.len() { // header: i < lines.len() let line = &lines[i]; // body if !line.trim().is_empty() { notes.push(parse(line)); // then } i += 1; // next } notes // exit}function load(file: string): Note[] { const lines = read(file); // entry const notes: Note[] = []; for (let i = 0; i < lines.length; i++) { // header: i < lines.length const line = lines[i]; // body if (line.trim() !== "") { notes.push(parse(line)); // then } } // next: i++ return notes; // exit}List<Note> Load(string file){ string[] lines = Read(file); // entry var notes = new List<Note>(); for (int i = 0; i < lines.Length; i++) // header: i < lines.Length { string line = lines[i]; // body if (!string.IsNullOrWhiteSpace(line)) { notes.Add(Parse(line)); // then } } // next: i++ return notes; // exit}The graph cfg holds its control flow. This control-flow graph has a node for each
basic block. Its loop consists of header, body, then and
next. The loop is an SCC, which is the gray frame. Every edge inside it lies on a cycle and is
orange. Which edges and blocks does the loop need so that its blocks still reach each other? The
picture after shows the strong bridges as green edges and the strong articulation points as green
blocks. body -> next stays orange, since it lies on a cycle but is not a strong bridge.
- SCC
- Edge on a cycle
- Strong articulation point
- Strong bridge
Solution
Section titled “Solution”The analysis follows edges against their direction as well, so it takes a
BiAdjacentGraphBiAdjacentGraphBiAdjacentGraphBiAdjacentGraph, which BiAdjacentGraph.ofBiAdjacentGraph::ofBiAdjacentGraph.ofBiAdjacentGraph.Of builds:
// The loop of cfg - header, body, then, next - is a strongly connected component. The// analysis follows edges against their direction too.StrongConnectivity strong = Components.strongConnectivityOf(BiAdjacentGraph.of(cfg));Edges strongBridges = strong.strongBridges();// strongBridges: header -> body, body -> then, then -> next, next -> headerSortedIntView strongArticulationPoints = strong.strongArticulationPoints();// strongArticulationPoints: [1, 2, 4] - header, body and next// The loop of cfg - header, body, then, next - is a strongly connected component. The// analysis follows edges against their direction too.let strong = components::strong_connectivity_of(&BiAdjacentGraph::of(&cfg));let strong_bridges = strong.strong_bridges();// strong_bridges: header -> body, body -> then, then -> next, next -> headerlet strong_articulation_points = strong.strong_articulation_points();// strong_articulation_points: [1, 2, 4] - header, body and next// The loop of cfg - header, body, then, next - is a strongly connected component. The// analysis follows edges against their direction too.const strong = Components.strongConnectivityOf(BiAdjacentGraph.of(cfg));const strongBridges = strong.strongBridges;// strongBridges: header -> body, body -> then, then -> next, next -> headerconst strongArticulationPoints = strong.strongArticulationPoints;// strongArticulationPoints: [1, 2, 4] - header, body and next// The loop of cfg - header, body, then, next - is a strongly connected component.// The analysis follows edges against their direction too.StrongConnectivity strong = Components.StrongConnectivityOf(BiAdjacentGraph.Of(cfg));Edges strongBridges = strong.StrongBridges;// strongBridges: header -> body, body -> then, then -> next, next -> headerSortedIntView strongArticulationPoints = strong.StrongArticulationPoints;// strongArticulationPoints: [1, 2, 4] - header, body and nextThe result has four strong bridges and three strong articulation points. They are the green edges
and blocks of the picture after. Without any of the four edges of the cycle
header -> body -> then -> next -> header, the loop is no longer one SCC. Without body -> next,
it still is, since the path body -> then -> next remains. Likewise,
without the block then, the other three blocks still reach each other through body -> next.
Without header, body or next, they do not.
Good to know
Section titled “Good to know”- Only inside SCCs. Strong bridges lie inside SCCs of two or more nodes. Strong articulation points lie inside SCCs of three or more: without one node of an SCC of two, the other node still forms one SCC. A graph without cycles has neither, and a self-loop is never a strong bridge.
- Two directions, two edges. The edges
a -> bandb -> acount as two edges here, and both are strong bridges of the SCC they form. - Undirected counterparts. In the undirected reading, where the direction does not matter, bridges and articulation points play the same role. See Find the edges and nodes whose removal splits a graph.
- Whether the graph is one SCC at all. See Check whether every node reaches every other.
API used
Section titled “API used”BiAdjacentGraph.of(Graph)BiAdjacentGraph::ofBiAdjacentGraph.ofBiAdjacentGraph.OfComponents.strongConnectivityOf(BiAdjacentGraph)components::strong_connectivity_ofComponents.strongConnectivityOfComponents.StrongConnectivityOfStrongConnectivity.strongBridges()StrongConnectivity::strong_bridgesStrongConnectivity.strongBridgesStrongConnectivity.StrongBridgesStrongConnectivity.strongArticulationPoints()StrongConnectivity::strong_articulation_pointsStrongConnectivity.strongArticulationPointsStrongConnectivity.StrongArticulationPoints