Walks, Paths and Connectivity

Study Sheet

Walks, Paths and Connectivity

Walks and paths, components, counting walks with matrices, and weak points of a network

Walks, Trails, Paths and Cycles

Concept
Walks, trails, paths and cycles
pqrst
The pentagon p q r s tp\,q\,r\,s\,t with one chord, qsqs.

A walk is a sequence v0,e1,v1,e2,…,ek,vkv_0, e_1, v_1, e_2, \ldots, e_k, v_k with each eie_i the edge vi−1viv_{i-1}v_i; its length is the number kk of edges. A trail is a walk that repeats no edge; a path is a walk that repeats no vertex (so it repeats no edge either). A walk is closed if v0=vkv_0 = v_k; a closed path whose only repeat is v0=vkv_0=v_k, of length at least 33, is a cycle. The pentagon-with-chord pictured below, call it G1G_1, has 55 vertices and 66 edges.

Walk, trail and path nest inside one another — every path is a trail and every trail is a walk — because each extra adjective forbids one more kind of repetition. The distinction matters because the theorems ahead are each about a specific one of these: a shortest walk between two vertices is automatically a path, since a repeated vertex could always be cut out to shorten it, so "distance" between vertices is really a statement about paths; Euler's theorem (Topic 6) asks for a trail using every edge once; and Menger's theorem below is about counting paths, not walks.

Example
A walk that revisits an edge

In G1G_1, follow p→q→r→s→q→pp \to q \to r \to s \to q \to p. The edges used are pq,qr,rs,sq,qppq, qr, rs, sq, qp — but qpqp is the same edge as pqpq, used a second time. So this closed walk of length 55 is not a trail (and, since pp and qq each occur twice, not a path either).

Example
A trail that is not a path

Follow t→p→q→r→s→qt \to p \to q \to r \to s \to q. The five edges used, tp,pq,qr,rs,sqtp, pq, qr, rs, sq, are all different from each other, so this is a trail. But the vertex qq appears twice, as the third and the sixth stop, so it is not a path: the walk passes through qq on its way to rr, then returns to qq before finally stopping.

Example
Does G1G_1 have a 44-cycle?
pqrst
The 44-cycle p-q-s-tp\text{-}q\text{-}s\text{-}t, drawn bold.

A 44-cycle needs four distinct vertices joined in a closed loop. Try p,q,s,tp, q, s, t: the edges pqpq, qsqs, stst, tptp are all present in G1G_1 — the chord qsqs is exactly what makes this possible — and no vertex repeats before closing back to pp. So p→q→s→t→pp \to q \to s \to t \to p is a 44-cycle.

Example
Shortcutting a walk into a path

The walk p→q→s→q→rp \to q \to s \to q \to r has length 44 and ends at rr, but it visits qq twice. Delete everything between the two visits to qq — the detour q→s→qq \to s \to q — and what is left is p→q→rp \to q \to r, a path of length 22 from pp to rr, and in fact the shortest one, since pp and rr are not adjacent. This is why a shortest walk between two vertices is always a path: a repeated vertex always hides a shortcut.

Side note
Where it goes wrong

Length counts edges, not stops. The walk p→q→s→q→rp \to q \to s \to q \to r has 55 stops but length 44, and even that 44 overcounts the distinct vertices visited: only p,q,s,rp, q, s, r appear, with qq twice. It is also neither a trail nor a path, since the edge qsqs is used twice (once in each direction) and qq repeats.

Try it
Try it: classify a walk

What is r→s→t→p→q→rr \to s \to t \to p \to q \to r in G1G_1 — a walk, a trail, a path, or a cycle?

Show the answer

The five edges used, rs,st,tp,pq,qrrs, st, tp, pq, qr, are all distinct, so it is a trail; the only repeated vertex is rr, which is also the start and the end, so it is in fact a closed path — a cycle, of length 5\mathbf{5}.

Connected Components

Concept
Connected components

Vertices uu and vv are connected if some walk joins them. This is an equivalence relation on V(G)V(G) ("Why It Works" proves it), and its equivalence classes are the connected components of GG; GG itself is connected exactly when it has one component.

Reflexivity needs only the trivial length-00 walk from a vertex to itself; symmetry comes from walking a path backwards; transitivity from joining two walks end to end. Because it is an equivalence relation, the components partition V(G)V(G) with no overlaps and no vertex left out — even an isolated vertex, with no edges at all, is its own component of size 11. Listing the components, or testing whether two vertices share one, is exactly what breadth-first search computes (Topic 5).

Example
The components of HH
pqrstuvwz
Three pieces: a pentagon-with-chord, a triangle, and an isolated vertex z.

Let HH consist of three pieces glued by nothing at all: the pentagon-with-chord G1G_1 from the last section (connected internally by its 66 edges), a separate triangle on u,v,wu, v, w (edges uv,vw,wuuv, vw, wu), and a single vertex zz with no edges whatsoever. No edge joins any of the three groups, so HH has exactly 3\mathbf{3} components, of sizes 5\mathbf{5}, 3\mathbf{3} and 1\mathbf{1} — and 5+3+1=95+3+1=9 accounts for every one of its 99 vertices.

Example
How many edges to connect HH?
pqrstuvwz
Adding tu and uz (dashed) merges all three pieces into one.

HH has 99 vertices and 99 edges — the same count a connected graph on 99 vertices could have — yet it is not connected. Each new edge can join at most two different components into one, reducing the component count by at most 11; starting from 33 components, reaching 11 needs at least 3−1=23-1=2 new edges, and 22 is enough (for instance tutu and uzuz). So 2\mathbf{2} edges suffice, and no fewer will do.

Example
pp and uu are not connected

Is there a walk from pp to uu in HH? Every edge of HH lies entirely inside one of the three listed vertex sets, {p,q,r,s,t}\{p,q,r,s,t\}, {u,v,w}\{u,v,w\}, {z}\{z\}, so a walk starting at pp can never reach a vertex outside {p,q,r,s,t}\{p,q,r,s,t\} — in particular never uu. Contrast this with pp and tt, joined directly by the edge tptp: they are connected, and in fact adjacent.

Side note
Where it goes wrong

It is tempting to think enough edges guarantee a connected graph. HH has 99 edges on 99 vertices, more than the 88 a tree on 99 vertices would need (Topic 4), and is still disconnected. Edges only help if they cross between pieces; piling edges inside one piece, like the chord qsqs, does nothing for the pieces left out.

Try it
Try it: adding one edge

Add the single edge tutu to HH. How many components does the result have, and what are their sizes?

Show the answer

tutu merges the 55-vertex piece and the 33-vertex piece into one 88-vertex component; zz is untouched. So there are 2\mathbf{2} components, of sizes 8\mathbf{8} and 1\mathbf{1}.

Counting Walks with Matrix Powers

Concept
Counting walks with a matrix

If AA is the adjacency matrix of GG (Topic 1), with rows and columns indexed by V(G)V(G), then for every k≥1k \ge 1 the entry (Ak)ij(A^k)_{ij} equals the number of walks of length kk from ii to jj. In particular the diagonal entries (Ak)ii(A^k)_{ii} count closed walks at ii.

The reason is the same one that makes matrix multiplication the right operation at all: (Ak)ij=∑ℓ(Ak−1)iℓAℓj(A^k)_{ij} = \sum_\ell (A^{k-1})_{i\ell} A_{\ell j} sums, over every neighbor ℓ\ell of jj, the walks of length k−1k-1 from ii to ℓ\ell followed by the one edge ℓj\ell j — exactly the walks of length kk that end at jj by way of ℓ\ell. "Why It Works" turns this into an induction on kk. The payoff is that a question about paths through a whole graph becomes ordinary arithmetic, and it is this fact that makes the adjacency matrix (introduced for its own sake in Topic 1) earn its keep.

Example
Building AA for a small graph
wxyz
Two triangles, wxz and xyz, sharing edge x-z.

The graph on w,x,y,zw,x,y,z with edges wx,xy,yz,zw,xzwx, xy, yz, zw, xz is two triangles, wxzwxz and xyzxyz, sharing the edge xzxz — sometimes called a diamond. In the vertex order w,x,y,zw,x,y,z its adjacency matrix is

A=(0101101101011110).A = \begin{pmatrix} 0&1&0&1\\ 1&0&1&1\\ 0&1&0&1\\ 1&1&1&0 \end{pmatrix}.
Example
Squaring AA

Row ww of A2A^2 comes from (A2)wj=∑ℓAwℓAℓj(A^2)_{wj} = \sum_\ell A_{w\ell}A_{\ell j}, summed over ww's neighbors ℓ∈{x,z}\ell \in \{x,z\}. For j=yj=y: (A2)wy=AwxAxy+AwzAzy=1⋅1+1⋅1=2(A^2)_{wy} = A_{wx}A_{xy} + A_{wz}A_{zy} = 1\cdot1 + 1\cdot1 = 2 — the walks w-x-yw\text{-}x\text{-}y and w-z-yw\text{-}z\text{-}y, matching the 22 common neighbors of ww and yy. The full matrix is

A2=(2121131221211213),A^2 = \begin{pmatrix} 2&1&2&1\\ 1&3&1&2\\ 2&1&2&1\\ 1&2&1&3 \end{pmatrix},

and its diagonal, 2,3,2,32,3,2,3, is exactly the degree sequence: a closed walk of length 22 at vv is "step out an edge, step straight back," and there are deg⁡(v)\deg(v) choices of which edge.

Example
How many triangles does the diamond contain?

In a simple graph, a closed walk of length 33 can never repeat a vertex (two equal vertices among v0,v1,v2v_0,v_1,v_2 would force a loop or a repeated edge within a single step), so every closed length-33 walk is a genuine triangle, traversed from one of its 33 vertices in one of 22 directions — 66 walks per triangle. So the number of triangles is tr⁡(A3)/6\operatorname{tr}(A^3)/6. Computing A3=A2AA^3=A^2A gives diagonal 2,4,2,42,4,2,4, so tr⁡(A3)=2+4+2+4=12\operatorname{tr}(A^3) = 2+4+2+4=12, and the diamond has 12/6=212/6=\mathbf{2} triangles — exactly wxzwxz and xyzxyz, as expected.

Example
Counting one entry by hand

(A3)wx=5(A^3)_{wx} = 5. Check this by listing every length-33 walk from ww to xx: starting w-x-□-xw\text{-}x\text{-}\Box\text{-}x gives w-x-w-xw\text{-}x\text{-}w\text{-}x, w-x-y-xw\text{-}x\text{-}y\text{-}x, w-x-z-xw\text{-}x\text{-}z\text{-}x; starting w-z-□-xw\text{-}z\text{-}\Box\text{-}x gives w-z-w-xw\text{-}z\text{-}w\text{-}x and w-z-y-xw\text{-}z\text{-}y\text{-}x (w-z-x-xw\text{-}z\text{-}x\text{-}x is not a walk, since x-xx\text{-}x is not an edge). That is 55 walks in all, matching the matrix entry.

Side note
Where it goes wrong

tr⁡(A2)=10\operatorname{tr}(A^2) = 10 is not a count of anything but the edges, doubled: it equals ∑vdeg⁡(v)=2∣E∣\sum_v \deg(v) = 2|E| by the handshake lemma (Topic 1), since every edge contributes exactly one there-and-back walk from each of its two ends. There are zero genuine 22-vertex cycles in a simple graph, so unlike tr⁡(A3)\operatorname{tr}(A^3), the trace of A2A^2 never counts cycles.

Try it
Try it: an entry by symmetry

Without recomputing, find (A3)yz(A^3)_{yz}.

Show the answer

Swapping w↔yw \leftrightarrow y and fixing x,zx,z is an automorphism of the diamond, since ww and yy have the same neighbors, {x,z}\{x,z\}. So (A3)yz=(A3)wz=5(A^3)_{yz} = (A^3)_{wz} = \mathbf{5}.

Cut Vertices and Bridges

Concept
Cut vertices and bridges

A vertex vv of a connected graph GG is a cut vertex if G−vG - v — delete vv and every edge at vv — is disconnected. An edge ee is a bridge if G−eG - e is disconnected. Both are single points of failure: removing one breaks the whole graph into pieces.

A connected graph with no cut vertex and no bridge has some redundancy built in: between any two vertices there is more than one way around, made precise by Menger's theorem below. Cut vertices and bridges are where that redundancy runs out. Topic 5's depth-first search finds every one of them in a single pass, by tracking how far back up the search tree each vertex can still reach.

Example
Find every cut vertex and bridge of GG
abcdefg
The cut vertices c, d, f shaded; the bridges cd, fg bold.

Let GG be the graph on a,…,ga,\ldots,g with edges ab,bc,ca,cd,de,ef,fd,fgab, bc, ca, cd, de, ef, fd, fg — two triangles joined by a bridge, with a pendant hanging off the second. Test each vertex by deleting it and checking what is left connected: deleting aa, bb or ee leaves the rest joined through the other triangle edges, so none of these is a cut vertex. Deleting cc splits off {a,b}\{a,b\} from {d,e,f,g}\{d,e,f,g\}; deleting dd splits {a,b,c}\{a,b,c\} from {e,f,g}\{e,f,g\}; deleting ff splits off gg alone. So the cut vertices are c,d,f\mathbf{c, d, f}. The same test on edges shows only cdcd and fgfg disconnect GG when removed — every other edge sits inside one of the two triangles, which stays connected without any one of its edges — so the bridges are cd\mathbf{cd} and fg\mathbf{fg}.

Example
A leaf is never a cut vertex

The bridge fgfg has two ends, but only one, ff, is a cut vertex. gg has degree 11, and deleting a degree-11 vertex can never disconnect what remains, since nothing else depended on reaching through it. In general, an endpoint of a bridge fails to be a cut vertex exactly when it is a leaf — compare cc and dd, the two ends of the other bridge cdcd, both of degree 33 and both cut vertices.

Example
A cut vertex need not touch any bridge
hijkl
No edge here is a bridge, yet h is a cut vertex.

In the "bowtie" graph on h,i,j,k,lh,i,j,k,l with two triangles, h,i,jh,i,j and h,k,lh,k,l, sharing only the vertex hh, every edge lies inside a triangle, so there is no bridge at all. Yet hh is a cut vertex: deleting it separates {i,j}\{i,j\} from {k,l}\{k,l\}. So a cut vertex need not be the endpoint of any bridge.

Side note
Where it goes wrong

Assuming every bridge endpoint is a cut vertex. gg is an endpoint of the bridge fgfg but, as a leaf, removing it changes nothing about the rest of GG; it is ff, the other end, that is the cut vertex.

Try it
Try it: a path graph

Find the cut vertices and bridges of the path 1-2-3-4-51\text{-}2\text{-}3\text{-}4\text{-}5 (edges 12,23,34,4512,23,34,45).

Show the answer

A path has no alternate route around any vertex or edge, so every internal vertex is a cut vertex, {2,3,4}\mathbf{\{2,3,4\}}, and every one of its 4\mathbf{4} edges is a bridge. (Topic 4 proves this holds for every edge and every non-leaf vertex of any tree.)

Connectivity and Menger's Theorem

Concept
Connectivity and Menger's theorem

The vertex connectivity κ(G)\kappa(G) is the smallest number of vertices whose removal disconnects GG (or leaves a single vertex); the edge connectivity λ(G)\lambda(G) is the smallest number of edges whose removal disconnects GG. Menger's theorem: for non-adjacent u,vu,v, the maximum number of pairwise internally-disjoint u-vu\text{-}v paths equals the minimum number of vertices, other than u,vu,v, whose removal separates them.

Connectivity turns the previous section's yes/no questions — is there a cut vertex? — into a number: κ(G)=1\kappa(G)=1 exactly when GG is connected and has a cut vertex, and κ(G)=0\kappa(G)=0 when GG is already disconnected. Menger's theorem is the deep fact underneath: having many disjoint routes between two vertices (a "max", hard to rule out) and having no small cut between them (a "min", easy to check one candidate at a time) turn out to be the exact same quantity. The same min-max phenomenon returns as max-flow–min-cut once edges carry capacities (Topic 10).

Example
Revisiting the last graph

For the graph GG of the last section, κ(G)=λ(G)=1\kappa(G)=\lambda(G)=1: removing the single cut vertex cc (or dd, or ff) disconnects it, removing the single bridge cdcd (or fgfg) disconnects it too, and no removal of 00 vertices or edges can disconnect a connected graph — so 11 is the smallest number that works, for vertices and for edges alike.

Example
Connectivity of a 66-cycle

Label the 66-cycle 1-2-3-4-5-6-11\text{-}2\text{-}3\text{-}4\text{-}5\text{-}6\text{-}1. Deleting any single vertex leaves a path on the other 55 vertices, still connected, so κ≥2\kappa \ge 2. Deleting the two opposite vertices 11 and 44 leaves only the edges 2323 and 5656, splitting {2,3}\{2,3\} from {5,6}\{5,6\} — so κ(C6)≤2\kappa(C_6) \le 2, and together κ(C6)=2\kappa(C_6)=2. The same two numbers work for edges: deleting one edge leaves a connected path, but deleting the two opposite edges 1212 and 4545 splits {2,3,4}\{2,3,4\} from {5,6,1}\{5,6,1\}, so λ(C6)=2\lambda(C_6)=2 as well.

Example
Menger's theorem for 11 and 44 in C6C_6
123456
Removing 2 and 6 leaves 1 isolated from 4.

The two arcs of the cycle give two paths from 11 to 44 sharing no internal vertex: 1-2-3-41\text{-}2\text{-}3\text{-}4 and 1-6-5-41\text{-}6\text{-}5\text{-}4. On the other side, removing the two vertices 22 and 66 leaves 11 with no edges at all, since its only neighbors were 22 and 66, while 3,4,53,4,5 stay joined by 34,4534,45 — so {2,6}\{2,6\} separates 11 from 44, and no single vertex can, since that would force κ(C6)≤1\kappa(C_6) \le 1. Both the maximum number of disjoint paths and the minimum separating set have size 2\mathbf{2}, exactly as Menger's theorem predicts.

Example
Connectivity of K4K_4
1234
K4: every pair of vertices has 3 independent routes.

In the complete graph K4K_4, every two vertices are already adjacent, so by convention κ(Kn)=n−1\kappa(K_n) = n-1; for K4K_4 that is κ=3\kappa=3. Between any two vertices, say 11 and 22, there are 33 pairwise internally-disjoint paths: the edge 1212 itself, and 1-3-21\text{-}3\text{-}2, 1-4-21\text{-}4\text{-}2 through the other two vertices — using all 44 vertices and giving exactly κ=3\kappa=3 independent routes.

Side note
Where it goes wrong

It is tempting to assume κ(G)=δ(G)\kappa(G) = \delta(G), the minimum degree, since removing the δ(G)\delta(G) neighbors of a minimum-degree vertex always disconnects it, giving κ(G)≤δ(G)\kappa(G) \le \delta(G) in general. But the inequality can be strict: join two triangles abcabc and defdef by a single bridge cdcd. Every vertex has degree 22 or 33, so δ=2\delta = 2, yet deleting the one cut vertex cc (or dd) disconnects the graph, so κ=1<2=δ\kappa = 1 < 2 = \delta.

Try it
Try it: a star

Find κ\kappa and λ\lambda for the star K1,4K_{1,4} (one hub joined to 44 leaves, no other edges).

Show the answer

Every leaf has degree 11, so δ=1\delta = 1, and both connectivities are squeezed down to it: removing the hub disconnects all 44 leaves from one another, and removing any single edge isolates that one leaf. So κ=λ=1\kappa = \lambda = \mathbf{1}.

Why It Works

Write u∼vu \sim v when some walk joins uu to vv. Reflexivity: the length-00 walk consisting of just uu joins uu to itself, so u∼uu \sim u. Symmetry: if v0,e1,…,ek,vkv_0, e_1, \ldots, e_k, v_k is a walk from u=v0u=v_0 to v=vkv=v_k, then reading it backwards, vk,ek,…,e1,v0v_k, e_k, \ldots, e_1, v_0, is a walk from vv to uu, since each eie_i joins the same two vertices regardless of the direction it is read — so v∼uv \sim u. Transitivity: if a walk joins uu to vv and another joins vv to ww, following the first to vv and then immediately the second gives a single walk from uu to ww, so u∼wu \sim w. Being reflexive, symmetric and transitive, ∼\sim is an equivalence relation, and the equivalence classes of any equivalence relation partition the underlying set with no overlaps and nothing left out — so the connected components partition V(G)V(G).

Induct on kk. Base case k=1k=1: (A1)ij=Aij(A^1)_{ij} = A_{ij}, which is 11 if ijij is an edge and 00 otherwise — exactly the number of walks of length 11 from ii to jj. Inductive step: suppose, for every vertex ℓ\ell, that (Ak−1)iℓ(A^{k-1})_{i\ell} counts the walks of length k−1k-1 from ii to ℓ\ell. A walk of length kk from ii to jj is exactly a walk of length k−1k-1 from ii to some neighbor ℓ\ell of jj, followed by the edge ℓj\ell j; every length-kk walk from ii to jj arises this way for exactly one ℓ\ell, namely its second-to-last vertex. So the number of length-kk walks from ii to jj is ∑ℓ∼j(Ak−1)iℓ=∑ℓ(Ak−1)iℓAℓj\sum_{\ell \sim j} (A^{k-1})_{i\ell} = \sum_\ell (A^{k-1})_{i\ell} A_{\ell j}, since AℓjA_{\ell j} is 11 exactly when ℓ∼j\ell \sim j and 00 otherwise — and that sum is (Ak−1A)ij=(Ak)ij(A^{k-1}A)_{ij} = (A^k)_{ij} by the definition of matrix multiplication. By induction the claim holds for every k≥1k \ge 1.

Let e=uve=uv be an edge of a connected graph GG. If ee lies on a cycle CC, then C−eC-e is a u-vu\text{-}v path avoiding ee, so any walk that uses ee can be rerouted around it using C−eC-e in its place; every pair of vertices joined by a walk in GG is still joined by one in G−eG-e, so deleting ee changes nothing about connectivity and ee is not a bridge. Conversely, if ee is not a bridge, then G−eG - e has the same components as GG, so in particular uu and vv, the two endpoints of ee, are still joined by some path PP in G−eG-e. Since PP lies in G−eG-e it does not use ee, so PP together with the edge ee is a closed walk through uu and vv with no repeated vertex except the shared start and end — a cycle containing ee. So ee lies on a cycle if and only if it is not a bridge.

Suppose P1,…,PkP_1, \ldots, P_k are pairwise internally-disjoint u-vu\text{-}v paths, and SS is any set of vertices, excluding uu and vv, whose removal leaves no u-vu\text{-}v path. Each PiP_i has both endpoints outside SS (since u,v∉Su,v \notin S); if PiP_i had no internal vertex in SS, it would survive intact in G−SG-S, contradicting that SS separates uu from vv. So every PiP_i contributes at least one internal vertex to SS, and since the paths are pairwise internally disjoint, these contributed vertices are all different from each other. Hence ∣S∣≥k|S| \ge k. This holds for every separating set SS, in particular for a smallest one, so the minimum separator size is at least kk — and since kk was the size of an arbitrary family of pairwise internally-disjoint paths, the minimum separator size is at least the maximum number of such paths. The reverse inequality, that a separator this small is always achievable by that many disjoint paths, is the genuinely hard half of Menger's theorem.