Skip to content

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.

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.

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?

The calls, read as undirected
The large block, and the self-loops in no block
0: main1: parseArgs2: run3: load4: save5: show6: parse7: format8: read9: write
0: main1: parseArgs2: run3: load4: save5: show6: parse7: format8: read9: write
Context
  • Self-loop in no block
Output
  • 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.

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 edges
int 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]
Full example
// 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 edges
let 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"]
Full example
// 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 edges
const 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]
Full example
// 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 edges
int 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]
Full example

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.