5.2 Find the edges and nodes whose removal splits a graph
You find the bridges and articulation points: the edges and nodes whose removal splits a component of a graph read as undirected.
Problem
Section titled “Problem”You want to know which single edge or single node a graph cannot lose, because some nodes would no longer be connected to the others. The direction of the edges does not matter for this, so the graph is read as undirected. An edge whose removal splits a component in two is called a bridge. A node whose removal splits a component is called an articulation point. You need this to find:
- a cable or a router whose failure cuts a network in two;
- a single call that is all that connects two areas of a program;
- a module through which every path between two halves of a system passes.
Example
Section titled “Example”The example graph calls models the calls between the methods of a small program. It has an edge
from each method to each method it calls. Here, the graph is read as undirected. Without which
single call, and without which method, are some methods no longer connected to the others?
- Call on a cycle
- Articulation point
- Bridge
In the picture after, the bridges and the articulation points are green. The orange edges lie on a
cycle, and none of them is a bridge. Four of them are the calls through
run, save, format and show. The other two are the self-loops of
parse and format, and each of these is a cycle of its own.
Solution
Section titled “Solution”The analysis follows the edges in both directions, so it takes a BiAdjacentGraphBiAdjacentGraphBiAdjacentGraphBiAdjacentGraph,
which BiAdjacentGraph.ofBiAdjacentGraph::ofBiAdjacentGraph.ofBiAdjacentGraph.Of builds from the graph:
// The analysis reads the edges as undirected and follows them both ways, so it takes// a BiAdjacentGraph.Biconnectivity biconnectivity = Components.biconnectivityOf(BiAdjacentGraph.of(calls));Edges bridges = biconnectivity.bridges();// bridges: main -> parseArgs, main -> run, run -> load, load -> parse, load -> read,// save -> writeSortedIntView articulationPoints = biconnectivity.articulationPoints();// articulationPoints: [0, 2, 3, 4] - main, run, load and save// The analysis reads the edges as undirected and follows them both ways, so it takes// a BiAdjacentGraph.let biconnectivity = components::biconnectivity_of(&BiAdjacentGraph::of(&calls));let bridges = biconnectivity.bridges();// bridges: main -> parseArgs, main -> run, run -> load, load -> parse, load -> read,// save -> writelet articulation_points = biconnectivity.articulation_points();// articulation_points: [0, 2, 3, 4] - main, run, load and save// The analysis reads the edges as undirected and follows them both ways, so it takes// a BiAdjacentGraph.const biconnectivity = Components.biconnectivityOf(BiAdjacentGraph.of(calls));const bridges = biconnectivity.bridges;// bridges: main -> parseArgs, main -> run, run -> load, load -> parse, load -> read,// save -> writeconst articulationPoints = biconnectivity.articulationPoints;// articulationPoints: [0, 2, 3, 4] - main, run, load and save// The analysis reads the edges as undirected and follows them both ways, so it// takes a BiAdjacentGraph.Biconnectivity biconnectivity = Components.BiconnectivityOf(BiAdjacentGraph.Of(calls));Edges bridges = biconnectivity.Bridges;// bridges: main -> parseArgs, main -> run, run -> load, load -> parse,// load -> read, save -> writeSortedIntView articulationPoints = biconnectivity.ArticulationPoints;// articulationPoints: [0, 2, 3, 4] - main, run, load and saveSix calls are bridges: every call between two different methods except the four on the cycle through
run, save, format and show. Four methods are articulation points:
- Without
main,parseArgsis connected to no other method. - Without
run,mainandparseArgsare no longer connected to the rest. - Without
load, neitherparsenorreadis connected to another method. - Without
save,writeis connected to no other method.
Good to know
Section titled “Good to know”- Bridges and cycles. An edge is a bridge exactly if it lies on no cycle of the undirected
reading.
run -> saveis no bridge: without it,runandsaveare still connected throughshowandformat. - Edges in both directions. The edges
a -> bandb -> acount as one undirected edge, so a graph that stores both directions still has bridges. Of a bridge stored in both directions,Biconnectivity.bridgesBiconnectivity::bridgesBiconnectivity.bridgesBiconnectivity.Bridgeslists only the edge from the lower to the higher node ID. Self-loops are never bridges. - The biconnected components come from the same analysis. See Divide the edges of a graph into biconnected components.
- Following the direction, the same question is about strongly connected components. See Find the edges and nodes whose removal splits a strongly connected component.
API used
Section titled “API used”Components.biconnectivityOf(BiAdjacentGraph)components::biconnectivity_ofComponents.biconnectivityOfComponents.BiconnectivityOfBiconnectivity.bridges()Biconnectivity::bridgesBiconnectivity.bridgesBiconnectivity.BridgesBiconnectivity.articulationPoints()Biconnectivity::articulation_pointsBiconnectivity.articulationPointsBiconnectivity.ArticulationPointsBiAdjacentGraph.of(Graph)BiAdjacentGraph::ofBiAdjacentGraph.ofBiAdjacentGraph.Of