Walks, paths, cycles and connected graphs
In a network, when can you get from one point to another by following links, what is the shortest way, and when does the network fall into separate pieces?
Where you are 10 in Introductory graph theory
Why this exists
A graph records single links, but the questions people ask are about routes: can a visitor get from this pavilion to that one, by how few walkways, is there a loop back to the start, does the whole site hang together? Answering them needs exact words for a route, a way to stop a route revisiting points, and connected graphs and their pieces, the components.
Definition
The notation is that of Degree, the handshake lemma and complete graphs: G = (V, E) is a simple graph, with \lvert V \rvert vertices, \lvert E \rvert edges and degrees \deg(v); \delta(G) is the smallest degree.
- A walk of length k from u to v is a sequence of vertices (v_0, v_1, \ldots, v_k) with v_0 = u, v_k = v, and v_{i-1}v_i \in E for each i = 1, \ldots, k. The length k counts a repeated edge each time it is used. The single vertex (u) is a walk of length 0. The edges of the walk are the edges v_{i-1}v_i.
- A walk is closed if k \ge 1 and v_k = v_0.
- A trail is a walk that uses no edge twice.
- A path is a walk with no vertex repeated. It uses no edge twice, so every path is a trail.
- A cycle of length k is a closed walk (v_0, v_1, \ldots, v_k = v_0) with k \ge 3 in which v_0, v_1, \ldots, v_{k-1} are all different. Starting at another of its vertices or running it backward gives the same cycle.
- u and v are joined if some walk runs from u to v. G is connected if every two of its vertices are joined, and disconnected otherwise.
- A component of G is a class of the relation “is joined to” (Result 2) together with every edge of G between vertices of that class.
- The distance d(u, v) is the length of a shortest walk from u to v, and d(u, v) = \infty if u and v are not joined.
- For n \ge 3 the cycle graph C_n has vertices 0, 1, \ldots, n - 1, with i joined to i + 1 for each i, taken modulo n.
In a simple graph a cycle needs k \ge 3: a closed walk of length 1 would need a loop, and (u, v, u) uses uv twice.
Intuition
Yuma is laying out a summer fair: pavilions are vertices and covered walkways are edges. A walk is a stroll, listing each pavilion as it is reached. A trail never reuses a walkway; a path never returns to a pavilion; a cycle is a loop such as (C, E, F, C) in Figure 1.
A stroll that visits some pavilion twice wasted the steps between the visits; cutting them out leaves a shorter stroll with the same ends, and repeated cuts end at a path. Pavilions P, Q, R reach each other, and so do A to F, but nothing joins the two groups: they are the two components.
Results
1. Walks contain paths. Every walk from u to v contains a path from u to v whose edges are all edges of the walk. In particular every shortest walk is a path, so d(u, v) is the length of a shortest path.
2. Components. “Is joined to” is an equivalence relation on V. Every edge has both ends in one class, each component is connected, and G is connected exactly when it has one component.
3. Distance. d(u, u) = 0, d(u, v) = d(v, u), and d(u, w) \le d(u, v) + d(v, w) for all vertices u, v, w.
4. Many edges at every vertex force a cycle. If \delta(G) \ge 2, then G contains a cycle of length at least \delta(G) + 1.
5. Odd closed walks. Every closed walk of odd length contains a cycle of odd length, all of whose edges are edges of the walk.
6. Enough edges force connection. A graph with n vertices and more than \binom{n-1}{2} edges is connected. The bound is sharp: K_{n-1} together with one isolated vertex has exactly \binom{n-1}{2} edges and is disconnected.
Why it is true
Result 1. Proof. Among all walks from u to v whose edges are edges of the given walk, choose one of least length, (v_0, \ldots, v_k). Suppose v_i = v_j with i < j. Deleting v_{i+1}, \ldots, v_j leaves (v_0, \ldots, v_i, v_{j+1}, \ldots, v_k), still a walk from u to v (since v_i = v_j is adjacent to v_{j+1}), using only edges already used, and shorter by j - i \ge 1. That contradicts the choice, so the walk is a path. A shortest walk from u to v is itself such a choice, so it is a path. \square
Result 2. Proof. Reflexive: (u) is a walk. Symmetric: a walk read backward runs from v to u. Transitive: a walk from u to v followed by one from v to w, with v written once, runs from u to w. So V splits into Relations, equivalence classes and partitions. An edge uv is the walk (u, v), so its ends share a class. Every vertex of a walk from u is joined to u, so a walk between two vertices of a class lies, edges included, in that component: each component is connected. One class means every two vertices are joined. \square
Result 3. Use the walk (u), reversed walks, and a shortest walk from u to v followed by one from v to w (if either distance is \infty there is nothing to prove).
Result 4. Proof. Write \delta = \delta(G). Some vertex has a neighbor, so paths of length at least 1 exist. A path repeats no vertex, so there are finitely many paths; choose a longest, (v_0, v_1, \ldots, v_k), with k \ge 1. Every neighbor w of v_k lies on the path, or (v_0, \ldots, v_k, w) would be longer. So the at least \delta neighbors of v_k are among v_0, \ldots, v_{k-1}, and the earliest, v_i, has i \le k - \delta. Then (v_i, v_{i+1}, \ldots, v_k, v_i) is a cycle of length k - i + 1 \ge \delta + 1 \ge 3. \square Figure 2 shows a case with \deg(v_6) = 3.
Result 5. Proof. By Strong induction and well-ordering on the odd length k. Let W = (v_0, \ldots, v_k) be closed with k odd. A simple graph has no loops, so k \ge 3. If v_0, \ldots, v_{k-1} are all different, W is an odd cycle. Otherwise v_i = v_j for some 0 \le i < j \le k other than i = 0, j = k. Split W into the closed walks
of lengths j - i and k - (j - i). Both lie between 1 and k - 1 and they add to the odd number k, so one is odd. By the induction hypothesis it contains an odd cycle made of its edges, which are edges of W. \square
Result 6. Proof. Suppose G is disconnected. Let A be the vertex set of one component, with a vertices, 1 \le a \le n - 1, and B the other n - a. No edge joins A to B (Result 2), and the a(n - a) pairs with one end in each are exactly the pairs lost, so
Expanding (a - 1)(n - a - 1) \ge 0 gives a(n - a) \ge n - 1, so \lvert E \rvert \le \binom{n}{2} - (n - 1) = \binom{n-1}{2}. By contraposition, more edges force G to be connected. \square
Worked examples
Naming routes
In Figure 1, decide for each sequence whether it is a walk, and if so whether it is closed, a trail, a path or a cycle, and give its length: (a) (A, B, C, E, F, C, D); (b) (D, A, B, C, D, A); (c) (B, C, F, E); (d) (A, B, C, D, A); (e) (A, C, E); (f) (P, Q, P).
SolutionEach consecutive pair must be an edge; then look for repeats.
(a) The edges AB, BC, CE, EF, FC, CD are all in E and all different: a trail of length 6. Not a path, since C appears twice.
(b) The edges are DA, AB, BC, CD, DA: a walk of length 5, not a trail, since DA is used twice.
(c) BC, CF, FE are edges and no vertex repeats: a path of length 3.
(d) Closed, with A, B, C, D different: a cycle of length 4.
(e) AC is not an edge, so this is not a walk.
(f) A closed walk of length 2, neither a cycle nor a trail: it uses PQ twice.
Cutting a walk down to a path
The walk (E, C, B, A, D, C, F, E, C, D) in Figure 1 runs from E to D. Shorten it to a path by the method of Result 1, and find d(E, D).
SolutionThe steps EC, CB, BA, AD, DC, CF, FE, EC, CD are all edges, so this is a walk of length 9. Read from the left until a vertex appears that was already seen: C, in the sixth place, first seen in the second. Deleting from just after the first C through the second leaves (E, C, F, E, C, D), still a walk from E to D. Now E returns in the fourth place, and cutting gives (E, C, D), a path of length 2. As E and D are not adjacent, no walk of length 1 joins them, so d(E, D) = 2.
Finding the components and distances
A larger fair has pavilions a to l and walkways ae, bg, cj, di, ah, gl, eh, ik, bl, ej, fk, df. Find the components, the distance from a to each pavilion it can reach, and the fewest new walkways that would make the fair connected.
SolutionGrow the class of a one step at a time. Distance 0: a. Distance 1, its neighbors: e, h. Distance 2, new neighbors of those: j. Distance 3: c. Nothing new is adjacent to c, so the class of a is \{a, c, e, h, j\}, and each layer number is the distance from a.
Start again at the first pavilion not reached, b: then g, l, and nothing more. Then d: then f, i, then k. The components have vertex sets \{a, c, e, h, j\}, \{b, g, l\} and \{d, f, i, k\}, and all 12 walkways lie inside them, as Result 2 requires.
A new walkway merges at most two components, so it lowers their number by at most 1. Going from 3 to 1 needs at least 2 new walkways, and 2 suffice, for example ab and bd.
Finding an odd cycle inside an odd closed walk
The closed walk (B, C, F, E, C, D, A, B, A, B) in Figure 1 has odd length. Follow the proof of Result 5 to find an odd cycle among its edges.
SolutionThe steps are BC, CF, FE, EC, CD, DA, AB, BA, AB, so the length is 9. The vertex B repeats in places 0 and 7. Splitting there gives (B, C, F, E, C, D, A, B) of length 7 and (B, A, B) of length 2, and 7 + 2 = 9. Keep the odd one. In it C repeats in places 1 and 4, and splitting gives (C, F, E, C) of length 3 and (B, C, D, A, B) of length 4. The odd one repeats nothing before its return: it is the triangle on C, E, F.
How many walkways guarantee connection
A fair has 12 pavilions. Show that 56 walkways make it connected however they are placed, and 55 do not.
SolutionWith n = 12, Result 6 says more than \displaystyle \binom{11}{2} = \frac{11 \cdot 10}{2} = 55 edges force a connected graph, so 56 are enough. But 55 walkways can join every pair among 11 pavilions, which is K_{11}, leaving the twelfth isolated: a disconnected fair.
Boundaries
- Simple graphs. In a multigraph a loop is a cycle of length 1 and two edges between the same pair make a cycle of length 2; a walk must then name its edges, and the step k \ge 3 in the proof of Result 5 fails.
- Finite graphs. Result 4 needs a longest path. The infinite graph on the integers with i joined to i + 1 has every degree 2 and no cycle.
- One-way results. \delta(G) \ge 2 is enough for a cycle, not needed: a triangle plus a pendant edge has a cycle and \delta = 1. The even closed walk (u, v, u) contains no cycle.
- Distance lives inside a component. Between components d(u, v) = \infty.
Where this goes next
A trail through every edge is Euler paths and circuits; a path or cycle through every vertex is Hamiltonian paths and cycles. A connected graph with no cycle is a tree (Trees). Result 5 is the key to Bipartite graphs. Distance with lengths on the edges is Finding a shortest path, counting walks is Adjacency matrices and their powers, and cycle lengths help tell graphs apart in Graph isomorphism: when two drawings are the same graph.
Exercises
Walks, trails, paths and cycles
Exercises 1 to 5 use the graph H of Figure 3, with edges 12, 23, 34, 45, 15, 16, 36, 47.
- Decide for each whether it is a walk, a trail, a path or a cycle, and give its length: (a) (1, 2, 3, 6, 1); (b) (7, 4, 3, 6, 1, 2, 3); (c) (5, 4, 7, 4, 3); (d) (2, 3, 6, 4); (e) (6, 1, 5, 4, 7).
- Find d(7, v) for every vertex v of H.
- List every cycle of H with its length, and explain why there are no others.
- Shorten the walk (2, 1, 6, 3, 2, 1, 5, 4, 3, 6) to a path by the method of Example 2. Is the path you get a shortest one? Find d(2, 6).
- The closed walk (1, 2, 3, 6, 1, 5, 4, 3, 6, 1) has odd length. Find an odd cycle among its edges.
Connected graphs and components
- A graph has vertices 1, 2, \ldots, 10 and edges \{1, 4\}, \{4, 7\}, \{2, 9\}, \{5, 9\}, \{5, 8\}, \{3, 10\}, \{6, 10\}, \{3, 6\}. Find its components and d(2, 8).
- What is the largest number of edges a disconnected graph on 9 vertices can have? Give one.
- A fair has 20 pavilions. What is the fewest number of walkways that makes the fair connected however they are placed?
- A graph has 7 vertices and exactly three components. What is the largest number of edges it can have?
- In C_9, find d(0, 6), the largest distance between two vertices, and every vertex at that distance from 0.
Cycles from degrees
- Give a graph with \delta(G) = 3 in which no cycle is longer than 4, and explain why this shows Result 4 cannot be improved for \delta = 3.
- In H, the path (7, 4, 5, 1, 2, 3, 6) cannot be extended past 6. Use the argument of Result 4 to find a cycle through 6.
Reasoning
- Prove that a graph with at least one edge and no cycle has at least two vertices of degree 1.
- Prove that if a graph has exactly two vertices of odd degree, they are joined by a path.
- Let G be connected and let e be an edge on a cycle of G. Prove that removing e (and keeping every vertex) leaves a connected graph.
- Prove that every closed trail contains a cycle.
- Let (v_0, v_1, \ldots, v_k) be a shortest path from u to v. Prove that d(u, v_i) = i for each i.
- Let G have n vertices with \displaystyle \delta(G) \ge \frac{n - 1}{2}. Prove that G is connected.
- Refute with a counterexample: “every closed walk of even length at least 4 contains a cycle of even length.”
Answers
- (a) A cycle of length 4. (b) A trail of length 6: its edges 74, 43, 36, 61, 12, 23 are different, but 3 appears twice. (c) A walk of length 4, not a trail: 47 is used twice. (d) Not a walk: 64 is not an edge. (e) A path of length 4.
- d(7, 7) = 0, d(7, 4) = 1, d(7, 3) = d(7, 5) = 2, d(7, 1) = d(7, 2) = d(7, 6) = 3, by layers from 7 as in Example 3.
- Three: (1, 2, 3, 4, 5, 1) of length 5, (1, 2, 3, 6, 1) of length 4 and (1, 6, 3, 4, 5, 1) of length 5. No cycle uses 47, as \deg(7) = 1. A cycle through 6 uses 16, 36 and returns from 3 to 1 by 2 or by 4, 5; one avoiding 6 is the ring.
- Vertex 2 returns in the fifth place; one cut leaves (2, 1, 5, 4, 3, 6), a path of length 5. Not shortest: 2, 6 are not adjacent and (2, 3, 6) has length 2, so d(2, 6) = 2. Cutting gives a path, not always a shortest one.
- Length 9. Vertex 1 repeats in places 0 and 4; splitting gives (1, 2, 3, 6, 1) of length 4 and (1, 5, 4, 3, 6, 1), a cycle of length 5.
- Vertex sets \{1, 4, 7\}, \{2, 5, 8, 9\} and \{3, 6, 10\}; d(2, 8) = 3, along (2, 9, 5, 8).
- 28 = \binom{8}{2}, for example K_8 and one isolated vertex. More is impossible by Result 6.
- 172. More than \binom{19}{2} = 171 forces connection; with 171, K_{19} and an isolated pavilion is disconnected.
- 10, from K_5 and two isolated vertices. With component sizes a + b + c = 7 there are at most \binom{a}{2} + \binom{b}{2} + \binom{c}{2} edges; the sizes (5, 1, 1), (4, 2, 1), (3, 3, 1), (3, 2, 2) give 10, 7, 6, 5.
- d(0, j) = \min(j, 9 - j), so d(0, 6) = 3, along (0, 8, 7, 6). The largest distance is 4, reached from 0 at 4 and 5.
- K_4: degrees 3, and no cycle longer than 4 = \delta + 1, the length Result 4 promises.
- The neighbors of 6 are 3 and 1, both on the path (v_0, \ldots, v_6). The earliest is 1 = v_3, giving the cycle (1, 2, 3, 6, 1) of length 4.
- Choose a longest path (v_0, \ldots, v_k), so k \ge 1. A neighbor w \ne v_{k-1} of v_k would close a cycle if on the path and give a longer path if off it. So \deg(v_k) = 1, and likewise \deg(v_0) = 1. \square
- Let u, v be the two, and K the component of u. Every edge at a vertex of K lies in K, so degrees in K are degrees in G. By the handshake lemma in K, K has an even number of odd vertices, so another besides u, which can only be v. By Result 1 they are joined by a path. \square
- Let e = xy lie on the cycle (x, y, w_1, \ldots, w_m, x). Then (y, w_1, \ldots, w_m, x) joins y to x without e. In any walk of G, replace each use of e by this walk or its reverse. So vertices joined in G stay joined without e. \square
- In a closed trail (v_0, \ldots, v_k), v_0 = v_k, so some vertex repeats. Choose v_i = v_j, i < j, with j - i least, so v_i, \ldots, v_{j-1} are different. Then j - i \ne 1 (no loops) and j - i \ne 2 ((v_i, v_{i+1}, v_i) reuses an edge), so j - i \ge 3 and (v_i, \ldots, v_j) is a cycle. \square
- The walk (v_0, \ldots, v_i) gives d(u, v_i) \le i. A walk from u to v_i shorter than i, followed by (v_i, \ldots, v_k), would be a walk from u to v shorter than k = d(u, v). \square
- Suppose not. With two or more components, a smallest has a vertex set A with \displaystyle \lvert A \rvert \le \frac{n}{2}. A vertex of A has all its neighbors in A, so its degree is at most \displaystyle \frac{n}{2} - 1 < \frac{n - 1}{2}, a contradiction. \square
- On a triangle x, y, z, the closed walk (x, y, z, x, y, z, x) has length 6, but its edges form only the triangle, a cycle of length 3. (And (x, y, x, y, x) has length 4 and contains no cycle.)