Bridges and articulation points

Finds the edges and the vertices whose loss splits an undirected graph into more pieces, its single points of failure, from one depth-first search.

Time complexity O(V+E), gograph function gograph.UndirectedCuts.

connectivity.Bridges returns the bridges alone, and connectivity.ArticulationPoints the articulation points.

How it works

A bridge is an edge whose loss splits a network in two, and an articulation point is a vertex whose loss does. Network and power engineers look for them to find single points of failure: a cable or a switch with no way around it.

One depth-first search finds both. Each vertex gets a discovery time when the search reaches it, and a low value: the earliest discovery time it can reach by going down the search tree and then along one back edge. A back edge is an edge to a vertex already on the search path, so it is a way around the tree edges below that vertex. When a vertex is finished, its low value passes to the vertex it was reached from.

The rule compares the two numbers. When a child's low value is above its parent's discovery time, nothing below the child reaches the parent or above except through the edge between them, so that edge is a bridge. When it isn't below the parent's discovery time, nothing below the child gets past the parent, so the parent is an articulation point. The first vertex of the search has nothing above it, so it is an articulation point when it has more than one child in the search tree.

gograph.UndirectedCuts returns the bridges, each from parent to child in the order the search finishes them, and the articulation points in the graph's vertex order, in O(V+E). connectivity.Bridges and connectivity.ArticulationPoints return one of the two. A directed graph returns gograph.ErrNotUndirected, since a one-way edge has no other end to fall back on. Tarjan's strongly connected components use the same low value on directed graphs.

Maze

A maze of 30 cells in five rows, A to E, and six columns, 1 to 6, so C4 is row C, column 4. Each edge is an open passage between two cells. The way from A1 to E6 winds through most of the maze, and two short loops give a few cells a second route.

An undirected graph with 30 vertices and 31 edges.

Which passages and cells does the maze have no way around, so that walling one up cuts part of the maze off?

There are 21 bridges: A1 and A2; A2 and A3; A3 and B3; A4 and A5; A5 and A6; A6 and B6; B1 and C1; B2 and B1; B3 and B2; B4 and A4; and 11 more. Losing any one of the 21 articulation points splits the graph: A2, A3, A4, A5, A6, B1, B2, B3, B4, B6 and 11 more.

Step by step

  1. Start the search at A1, the first vertex. Its discovery time is 1, and its low value starts at 1: so far, the earliest discovery time it can reach is its own.
  2. A1 to A2 is a tree edge. Discover A2 at 2, with a low value of 2.
  3. A2 to A1 is the tree edge A2 was reached by, seen from this end. The search skips it, since it isn't a way around itself.
  4. A2 to A3 is a tree edge. Discover A3 at 3, with a low value of 3.
  5. A3 to B3 is a tree edge. Discover B3 at 4, with a low value of 4.
  6. B3 to B2 is a tree edge. Discover B2 at 5, with a low value of 5.

58 more steps lead to the last one:

  1. Done. The search found 21 bridges and 21 articulation points.

Use it in Go

bridges, points, err := gograph.UndirectedCuts(g)
if err != nil {
	return err // gograph.ErrNotUndirected
}
for _, e := range bridges {
	fmt.Println(e.Source().Label(), e.Destination().Label())
}
for _, v := range points {
	fmt.Println(v.Label())
}

Example graphs

More in Connectivity

  • Tarjan: Finds the strongly connected components of a directed graph, the groups of vertices that can all reach each other, with one depth-first search.
  • Kosaraju: Finds the strongly connected components of a directed graph with two depth-first searches, the second on the graph with every edge reversed.
  • Gabow: Finds the strongly connected components of a directed graph with one depth-first search and two stacks, without the lowlink values of Tarjan's algorithm.
  • Condensation: Replaces each strongly connected component with one vertex. What is left is a DAG, so it can be sorted and scheduled.
  • Connected components: Splits a graph into its connected pieces, the groups of vertices joined to each other by some path, with one search per piece.
  • Cycle detection: Says whether a graph has a cycle, a way to follow its edges from a vertex back to the same vertex, and stops at the first one it finds.
  • Find a cycle: Returns the vertices of one cycle in order: the first one a depth-first search closes with an edge back to its search path.

All algorithms