5.3 Divide the edges of a graph into biconnected components
You get the biconnected components of a graph read as undirected, also called blocks: groups of edges in which any two edges lie on a common cycle.
Problem
Section titled “Problem”You want to find the areas of a graph that stay connected when any one of their nodes is removed, whatever the direction of the edges. Such an area, as large as it can be, is called a biconnected component or block. The edges of a block form a group in which any two edges lie on a common cycle. The one exception is a single edge that lies on no cycle: it is a block of its own, called a bridge. Removing it splits the graph. A node that belongs to more than one block is called an articulation point. Removing it splits the graph as well. You need this to find:
- the groups of routers in a network that stay connected when any one router fails;
- the modules of a system that stay connected when any one of them fails.
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. The array names holds the names of the methods. Here,
the graph is read as undirected. Which calls lie on a common cycle and form a block together? Which
calls are blocks of their own?
- Self-loop in no block
- Call in the large block
In the picture after, the four green calls form the large block. Each of the other six calls between two different methods is a block of its own, and the two dashed self-loops are in no block.
Solution
Section titled “Solution”The blocks come from the same analysis as the bridges and articulation points. It follows the edges
in both directions, so it takes a BiAdjacentGraphBiAdjacentGraphBiAdjacentGraphBiAdjacentGraph, which
BiAdjacentGraph.ofBiAdjacentGraph::ofBiAdjacentGraph.ofBiAdjacentGraph.Of builds from the graph:
// The blocks come from the same analysis as the bridges.Biconnectivity biconnectivity = Components.biconnectivityOf(BiAdjacentGraph.of(calls));EdgePartition blocks = biconnectivity.blocks();// 7 - six blocks of one edge, one of four edgesint blockCount = blocks.groupCount();
// The edges other than self-loops that lie on a cycle, read as undirected: those of// the blocks of three edges or more. A bridge is a block of one edge, or of two if it// is stored in both directions.List<String> largeBlock = new ArrayList<>();for (int block = 0; block < blockCount; block++) { if (blocks.sizeOf(block) > 2) { for (int edge : blocks.edgesOf(block)) { largeBlock.add( names[calls.edgeSource(edge)] + " -> " + names[calls.edgeTarget(edge)]); } }}// largeBlock: [run -> save, run -> show, save -> format, show -> format]// The blocks come from the same analysis as the bridges.let biconnectivity = components::biconnectivity_of(&BiAdjacentGraph::of(&calls));let blocks = biconnectivity.blocks();// 7 - six blocks of one edge, one of four edgeslet block_count = blocks.group_count();
// The edges other than self-loops that lie on a cycle, read as undirected: those of// the blocks of three edges or more. A bridge is a block of one edge, or of two if it// is stored in both directions.let mut large_block = Vec::new();for block in 0..block_count { if blocks.size_of(block) > 2 { for &edge in blocks.edges_of(block).iter() { let caller = names[calls.edge_source(edge) as usize]; let callee = names[calls.edge_target(edge) as usize]; large_block.push(format!("{caller} -> {callee}")); } }}// large_block: ["run -> save", "run -> show", "save -> format", "show -> format"]// The blocks come from the same analysis as the bridges.const biconnectivity = Components.biconnectivityOf(BiAdjacentGraph.of(calls));const blocks = biconnectivity.blocks;// 7 - six blocks of one edge, one of four edgesconst blockCount = blocks.groupCount;
// The edges other than self-loops that lie on a cycle, read as undirected: those of// the blocks of three edges or more. A bridge is a block of one edge, or of two if it// is stored in both directions.const largeBlock: string[] = [];for (let block = 0; block < blockCount; block++) { if (blocks.sizeOf(block) > 2) { for (const edge of blocks.edgesOf(block)) { largeBlock.push( `${names[calls.edgeSource(edge)]} -> ${names[calls.edgeTarget(edge)]}`, ); } }}// largeBlock: [run -> save, run -> show, save -> format, show -> format]// The blocks come from the same analysis as the bridges.Biconnectivity biconnectivity = Components.BiconnectivityOf(BiAdjacentGraph.Of(calls));EdgePartition blocks = biconnectivity.Blocks;// 7 - six blocks of one edge, one of four edgesint blockCount = blocks.GroupCount;
// The edges other than self-loops that lie on a cycle, read as undirected: those// of the blocks of three edges or more. A bridge is a block of one edge, or of// two if it is stored in both directions.List<string> largeBlock = [];for (int block = 0; block < blockCount; block++){ if (blocks.SizeOf(block) > 2) { foreach (int edge in blocks.EdgesOf(block)) { largeBlock.Add( $"{names[calls.EdgeSource(edge)]} -> " + $"{names[calls.EdgeTarget(edge)]}"); } }}// largeBlock: [run -> save, run -> show, save -> format, show -> format]The calls form seven blocks. Six of them are single calls, which are the bridges. The seventh holds
the four calls on the cycle through run, save, format and show: any two of them lie on a
common cycle, and these four methods stay connected if any one of them is removed.
Good to know
Section titled “Good to know”- Edges, not nodes. An articulation point belongs to every block it touches:
runbelongs to three. So the blocks are a partition of the edges, and the result is anEdgePartitionEdgePartitionEdgePartitionEdgePartition.IndexPartition.groupCountIndexPartition::group_countIndexPartition.groupCountIndexPartition.GroupCountreturns the number of blocks, andIndexPartition.sizeOfIndexPartition::size_ofIndexPartition.sizeOfIndexPartition.SizeOfthe number of edges in a block.EdgePartition.edgeCountEdgePartition::edge_countEdgePartition.edgeCountEdgePartition.EdgeCountreturns the number of edges of the graph, whether in a block or not. - Self-loops are in no block: for a self-loop,
IndexMapping.getIndexMapping::getIndexMapping.getIndexMapping.Getreturns-1None-1-1instead of a block. Every other edge is in exactly one block. - Edges in both directions. The edges
a -> bandb -> acount as one undirected edge, and both are in the same block, so a bridge stored in both directions is a block of two edges. - Only the bridges and articulation points? They come from the same call. See Find the edges and nodes whose removal splits a graph.
API used
Section titled “API used”Components.biconnectivityOf(BiAdjacentGraph)components::biconnectivity_ofComponents.biconnectivityOfComponents.BiconnectivityOfBiconnectivity.blocks()Biconnectivity::blocksBiconnectivity.blocksBiconnectivity.BlocksIndexPartition.groupCount()IndexPartition::group_countIndexPartition.groupCountIndexPartition.GroupCountIndexPartition.sizeOf(int)IndexPartition::size_ofIndexPartition.sizeOfIndexPartition.SizeOfEdgePartition.edgesOf(int)EdgePartition::edges_ofEdgePartition.edgesOfEdgePartition.EdgesOfEdgePartition.edgeCount()EdgePartition::edge_countEdgePartition.edgeCountEdgePartition.EdgeCountIndexMapping.get(int)IndexMapping::getIndexMapping.getIndexMapping.GetBiAdjacentGraph.of(Graph)BiAdjacentGraph::ofBiAdjacentGraph.ofBiAdjacentGraph.OfGraph.edgeSource(int)Graph::edge_sourceGraph.edgeSourceGraph.EdgeSourceGraph.edgeTarget(int)Graph::edge_targetGraph.edgeTargetGraph.EdgeTarget