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.

Office network

Switches and rooms in a four-team office, wired through a core switch.

An undirected graph with 13 vertices and 16 edges.

Which single cable or switch would cut part of the office off if it failed?

There are 4 bridges: Dev and Dev 2; Ops and Ops 1; Sales and Sales 1; Support and Support 1. Losing any one of the 4 articulation points splits the graph: Dev, Ops, Sales and Support.

Step by step

  1. Start the search at Core, 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. Core to Sales is a tree edge. Discover Sales at 2, with a low value of 2.
  3. Sales to Core is the tree edge Sales was reached by, seen from this end. The search skips it, since it isn't a way around itself.
  4. Sales to Uplink is a tree edge. Discover Uplink at 3, with a low value of 3.
  5. Uplink to Support is a tree edge. Discover Support at 4, with a low value of 4.
  6. Support to Core is a back edge to Core, discovered at 1. That's earlier than Support's low value, 4, so its low value becomes 1.

26 more steps lead to the last one:

  1. Done. The search found 4 bridges and 4 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