AnyLearn
All lessons
Mathintermediate

Graph Connectivity: Bridges, Cut Vertices, and Menger's Theorem

Connected is only the first question; how much damage a graph can absorb is the useful one. Learn vertex and edge connectivity, find every bridge and cut vertex in one depth-first search, and see Menger's theorem turn minimum cuts into a count of disjoint paths.

Updated · AI-authored, review-gated · how lessons are made

Progress1 / 10

Connected is not a yes-or-no property

A graph is connected when every vertex can reach every other. That is a binary test, and it hides the question engineers actually care about: how much damage does it take to break the graph apart?

A path on 100 vertices and a 100-vertex cycle are both connected. Delete any one interior edge of the path and it splits in two; the cycle survives the loss of any single edge and only splits after two. Graph theory measures this robustness with two numbers.

Definition: The vertex connectivity κ(G)\kappa(G) is the fewest vertices whose removal disconnects GG (or leaves one vertex). The edge connectivity λ(G)\lambda(G) is the fewest edges whose removal disconnects it. A graph is kk-connected when κ(G)≥k\kappa(G) \ge k.

By these measures the path has κ=λ=1\kappa = \lambda = 1 and the cycle has κ=λ=2\kappa = \lambda = 2. Everything in this lesson is about computing these numbers, finding the weak points that set them, and the theorem that turns them into a count of independent routes.

Sign in free to save your progress and earn certificates.

Full lesson text

All 10 steps on one page, for reading, reference, and search.

Show

1. Connected is not a yes-or-no property

A graph is connected when every vertex can reach every other. That is a binary test, and it hides the question engineers actually care about: how much damage does it take to break the graph apart?

A path on 100 vertices and a 100-vertex cycle are both connected. Delete any one interior edge of the path and it splits in two; the cycle survives the loss of any single edge and only splits after two. Graph theory measures this robustness with two numbers.

Definition: The vertex connectivity κ(G)\kappa(G) is the fewest vertices whose removal disconnects GG (or leaves one vertex). The edge connectivity λ(G)\lambda(G) is the fewest edges whose removal disconnects it. A graph is kk-connected when κ(G)≥k\kappa(G) \ge k.

By these measures the path has κ=λ=1\kappa = \lambda = 1 and the cycle has κ=λ=2\kappa = \lambda = 2. Everything in this lesson is about computing these numbers, finding the weak points that set them, and the theorem that turns them into a count of independent routes.

2. Finding the pieces in linear time

Before measuring robustness you need the components themselves. Two standard tools do it, and they suit different situations.

BFS or DFS sweepUnion-find
Inputthe whole graph, up frontedges arriving one at a time
CostO(∣V∣+∣E∣)O(\lvert V\rvert + \lvert E\rvert) totalnear-constant amortised per edge
Answersfull component labels"are uu and vv connected yet?"
Handles deletionsrerun from scratchno, insert-only

The sweep is simple: start anywhere, label everything you can reach, then restart from any unlabelled vertex. Each vertex and edge is touched a constant number of times. Union-find keeps a forest of representatives; with union by rank and path compression, Tarjan (1975) proved the amortised cost per operation is bounded by the inverse Ackermann function, which, as Cormen et al. note in Introduction to Algorithms, is at most 4 for any practical input size.

In practice: Kruskal's minimum spanning tree algorithm is union-find in disguise. It asks "would this edge join two different components?" for every edge in weight order.

3. Bridges and cut vertices: single points of failure

When λ(G)=1\lambda(G) = 1 or κ(G)=1\kappa(G) = 1, there is a specific culprit.

  • A bridge is an edge whose removal increases the number of components. An edge is a bridge exactly when it lies on no cycle.
  • A cut vertex (or articulation point) is a vertex whose removal increases the number of components.
  • A graph with no cut vertex is biconnected. Its maximal biconnected pieces, the blocks, overlap only at cut vertices, and the blocks with the cut vertices between them always form a tree, the block-cut tree.

Every bridge with at least one non-leaf endpoint comes with a cut vertex, but the converse fails: two triangles sharing a single vertex have a cut vertex and no bridge at all.

In practice: This is the vocabulary of resilience audits. In a backbone network a bridge is a fibre link with no alternative route; in a road graph a cut vertex is the one junction that, if closed, isolates a town; in a software dependency graph it is the one package every subsystem reaches through.

4. The low-link trick

Testing every edge by deleting it and rerunning a sweep costs O(∣E∣(∣V∣+∣E∣))O(\lvert E\rvert(\lvert V\rvert+\lvert E\rvert)). Tarjan (1972) and Hopcroft and Tarjan (1973) found all bridges and cut vertices in a single depth-first search, in O(∣V∣+∣E∣)O(\lvert V\rvert + \lvert E\rvert).

Run DFS and record disc(u)\mathrm{disc}(u), the time each vertex is first discovered. In an undirected DFS every non-tree edge points back to an ancestor, so define

low(u)=min⁡(disc(u), disc(w) for any back edge from u’s subtree to w)\mathrm{low}(u) = \min\big(\mathrm{disc}(u),\ \mathrm{disc}(w) \text{ for any back edge from } u\text{'s subtree to } w\big)

the earliest ancestor reachable from uu's subtree using one back edge. Then, for a tree edge from parent uu to child vv:

  • (u,v)(u, v) is a bridge if and only if low(v)>disc(u)\mathrm{low}(v) > \mathrm{disc}(u): nothing below vv climbs back to uu or above.
  • A non-root uu is a cut vertex if and only if some child has low(v)≥disc(u)\mathrm{low}(v) \ge \mathrm{disc}(u).
  • The DFS root is a cut vertex if and only if it has two or more tree children.

Key idea: One number per vertex, computed bottom-up, summarises every escape route a subtree has. The same idea, extended to directed graphs, finds strongly connected components.

5. Bridges and cut vertices in Python

The three rules translate almost line for line. The graph below is a triangle A-B-C, joined by edge C-D to a triangle D-E-F, with a pendant vertex G hanging off F.

def bridges_and_cuts(adj):
    disc, low = {}, {}
    bridges, cuts = [], set()
    timer = 0

    def dfs(u, parent):
        nonlocal timer
        disc[u] = low[u] = timer
        timer += 1
        children = 0
        for v in adj[u]:
            if v == parent:
                continue
            if v in disc:                      # back edge
                low[u] = min(low[u], disc[v])
            else:                              # tree edge
                children += 1
                dfs(v, u)
                low[u] = min(low[u], low[v])
                if low[v] > disc[u]:
                    bridges.append((u, v))
                if parent is not None and low[v] >= disc[u]:
                    cuts.add(u)
        if parent is None and children > 1:
            cuts.add(u)

    for s in adj:
        if s not in disc:
            dfs(s, None)
    return bridges, cuts

adj = {"A": "BC", "B": "AC", "C": "ABD", "D": "CEF",
       "E": "DF", "F": "DEG", "G": "F"}
print(bridges_and_cuts(adj))
# ([('F', 'G'), ('C', 'D')], {'C', 'D', 'F'})

NetworkX gives the same answer with nx.bridges(G) and nx.articulation_points(G).

6. Whitney's inequality, and when the gap opens

Whitney (1932) proved that the two connectivities and the minimum degree δ(G)\delta(G) are always ordered:

κ(G)  ≤  λ(G)  ≤  δ(G)\kappa(G) \;\le\; \lambda(G) \;\le\; \delta(G)

The right inequality is immediate: deleting every edge at a minimum-degree vertex isolates it. The left one holds because for any minimum edge cut one endpoint of each cut edge, chosen carefully, gives a vertex separator that is no larger.

Predict first

Take two copies of the complete graph K4K_4 and glue them at a single shared vertex. What are κ\kappa, λ\lambda and δ\delta?

Gotcha: A high minimum degree says nothing about vertex connectivity. Redundant links per node do not help if they all lead through the same hub.

7. Menger's theorem: cuts equal disjoint paths

Connectivity is defined by what you must destroy. Menger (1927) showed it equals what survives: the number of independent routes.

Key idea: For non-adjacent vertices ss and tt, the minimum number of vertices whose removal separates ss from tt equals the maximum number of ss-tt paths that share no vertex except ss and tt. The edge version replaces both "vertices" with "edges".

One direction is obvious: if there are kk disjoint paths, any separator must hit each one, so it has at least kk vertices. The content is the other direction, that a small cut always exists when paths are scarce. Applying it to every pair gives the global form, proved by Whitney (1932): a graph is kk-connected if and only if every pair of vertices is joined by kk internally disjoint paths.

This is the first appearance of a pattern that runs through the whole of combinatorial optimisation: a max-min duality, where the best packing of one kind of object equals the smallest blocking set of another, and each side certifies the other. The next lesson computes both sides with a single algorithm: maximum flow.

8. Directed graphs: strong components and the condensation

In a directed graph, reachability is not symmetric, so "connected" splits in two. A graph is weakly connected if it is connected once arrows are ignored, and strongly connected if every vertex reaches every other along the arrows. The strongly connected components (SCCs) partition the vertices, and collapsing each SCC to one node always yields a DAG, the condensation, shown here. Tarjan's algorithm (1972) and Kosaraju's two-pass algorithm both find every SCC in O(∣V∣+∣E∣)O(\lvert V\rvert + \lvert E\rvert). Once you have the condensation, any DAG technique, such as topological order, applies to the original graph.

flowchart LR
  S1["SCC 1: a, b, c"] --> S2["SCC 2: d, e"]
  S1 --> S3["SCC 3: f"]
  S2 --> S4["SCC 4: g, h, i"]
  S3 --> S4
  S4 --> S5["SCC 5: j"]

9. Global minimum cut without fixing s and t

Menger answers "how robust is the link between ss and tt?" The edge connectivity λ(G)\lambda(G) asks for the weakest pair overall. Running a pairwise computation from one fixed vertex to every other works, but two algorithms do better.

Stoer-Wagner (1997)Karger contraction (1993)
Typedeterministicrandomised
Idearepeatedly find the most tightly connected vertex order, merge the last twocontract a uniformly random edge until two super-vertices remain
CostO(∣V∣∣E∣+∣V∣2log⁡∣V∣)O(\lvert V\rvert\lvert E\rvert + \lvert V\rvert^2 \log \lvert V\rvert), per Stoer and Wagnerone run is cheap; repeat many times
Guaranteeexacta given min cut survives one run with probability at least (n2)−1\binom{n}{2}^{-1}, per Karger

Karger's bound is small for one run, but repeating (n2)ln⁡n\binom{n}{2}\ln n times drives the failure probability below 1/n1/n, and the analysis has a striking corollary: a graph has at most (n2)\binom{n}{2} distinct minimum cuts.

In practice: NetworkX exposes nx.stoer_wagner(G) for weighted undirected graphs, and nx.edge_connectivity(G) and nx.node_connectivity(G) for the unweighted counts.

10. Mistakes that give wrong answers

The algorithms are linear and exact. The errors come from the modelling around them.

Gotcha: Recursive DFS on a long path overflows the call stack. CPython's default recursion limit is 1000 frames, per the Python documentation for sys.getrecursionlimit, so the code in this lesson fails on a path of a few thousand vertices. Production code uses an explicit stack.

  • Parallel edges. In a multigraph, skipping "the parent" by vertex identity wrongly ignores a second edge to the parent, and a doubled link gets reported as a bridge. Skip the parent edge by its id instead.
  • Direction. Bridges and cut vertices are undirected notions. For directed graphs ask about strong connectivity, or the directed versions of Menger, which the next lesson handles with flows.
  • Weighted robustness. A link with capacity 1 and a link with capacity 100 both count as one edge in λ(G)\lambda(G). If capacities matter, you want a minimum weight cut, which is the flow problem.
  • Isolated vertices. A graph with an isolated vertex has λ=κ=0\lambda = \kappa = 0, and some libraries raise errors rather than return zero. Check components first.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. In a DFS of an undirected graph, tree edge (u, v) has disc(u) = 4 and low(v) = 4. What does that tell you?
    • The edge (u, v) is a bridge
    • The edge (u, v) is not a bridge, and u is a cut vertex if it is not the root
    • Neither u nor v can be a cut vertex
    • v is a cut vertex because its low value equals its parent's discovery time
  2. Which statement about Whitney's inequality kappa <= lambda <= delta is correct?
    • All three quantities are always equal in a connected graph
    • Edge connectivity can exceed the minimum degree in dense graphs
    • Two copies of K4 glued at one vertex have kappa = 1 but lambda = 3
    • Vertex connectivity is always at least the edge connectivity
  3. What does Menger's theorem equate for two non-adjacent vertices s and t?
    • The minimum s-t vertex separator size and the maximum number of internally vertex-disjoint s-t paths
    • The shortest s-t path length and the number of s-t paths
    • The degree of s and the degree of t
    • The number of bridges and the number of cut vertices on s-t paths
  4. You collapse every strongly connected component of a directed graph into a single node. What structure do you always get?
    • A tree rooted at the largest component
    • A strongly connected graph
    • A bipartite graph
    • A directed acyclic graph
  5. A network has 50 routers and edges arrive in a stream; you only need to answer 'are these two routers connected yet?'. Which tool fits best?
    • Rerunning a full BFS after each edge
    • Union-find with union by rank and path compression
    • Karger's contraction algorithm
    • Tarjan's strongly connected components algorithm

Related lessons

Math
intermediate

Network Flows: Augmenting Paths and the Max-Flow Min-Cut Theorem

Why pushing flow greedily gets stuck, how the residual graph makes every decision reversible, and why the maximum flow always equals the minimum cut. Build Edmonds-Karp in Python, compare the classic algorithms, and see cuts solve image segmentation and project selection.

10 steps·~15 min
Math
advanced

Spectral Graph Theory: What the Laplacian's Eigenvalues Reveal

Turn a graph into its Laplacian matrix and its eigenvalues start answering combinatorial questions: how many components, how many spanning trees, how hard the graph is to cut, and where to cut it. Covers the Fiedler vector, Cheeger's inequality, spectral clustering, random-walk mixing, and expanders.

10 steps·~15 min
Math
intermediate

Matching: Augmenting Paths, Hall, König, and the Assignment Problem

Pair workers with tasks, the most pairs or the cheapest total. Learn why augmenting paths prove a matching is maximum, how Hall's and König's theorems give certificates, how the Hungarian method prices an assignment, and why odd cycles and preferences each change the problem.

10 steps·~15 min
Math
intermediate

Graphs: A Language for Relationships

A graph is two sets and an incidence relation, and that austerity is why the same object models build dependencies, social networks, register allocation and road maps. This lesson covers the structural properties worth knowing, the special families that make hard problems easy, and the line where a small change to a question makes it intractable.

10 steps·~15 min