Paths, Distance, and Shortest Routes
Walks, trails, paths, and cycles defined precisely, connected components, and the distance between two vertices. Breadth-first search computes distances layer by layer and proves the odd cycle characterization of bipartite graphs; Dijkstra's algorithm finds the shortest route through a weighted network, with the invariant that makes it correct. The unit closes with the small world: how many intermediaries separate two people on Earth, and how that was measured.
Unit 1 used paths and cycles only as subgraphs, small copies of \(P_k\) and \(C_k\) sitting inside a larger graph. In this unit they become routes along which a traveller moves. A route through a graph is a sequence of vertices in which each is adjacent to the next, and the questions that follow are the ones a traveller asks: can one get from here to there at all, how many edges does the shortest way have, and how is that shortest way found when the graph has a million vertices and nobody can draw it? The answers are a handful of definitions that have to be made with care, two algorithms, and one of the most quoted numbers of the social sciences, the number of intermediaries that separate two strangers.
1 Walks, trails, paths, and cycles
A walk in a graph \(G\) is a sequence of vertices \(v_0, v_1, \ldots, v_k\) in which every two consecutive vertices are adjacent, that is, \(v_{i-1} v_i\) is an edge for \(i = 1, \ldots, k\). The walk starts at \(v_0\), ends at \(v_k\), and its length is \(k\), the number of edges it uses, counted with repetition, so that an edge used twice counts twice. A walk may repeat vertices and edges any number of times; the walk \(a, b, c, b, d\) in Figure 1(a) uses the edge \(bc\) twice and has length 4. A walk with \(v_0 = v_k\) is closed. The walk with a single vertex and no edge is allowed and has length 0.
Three more words single out walks that do not repeat themselves. A trail is a walk in which no edge is used twice; vertices may still repeat, as the vertex \(d\) does in the trail \(a, d, c, b, d, e\) of Figure 1(b). A path is a walk in which no vertex is repeated, and therefore no edge either; the path \(a, b, d, e, f\) in Figure 1(c) has length 4 and is a copy of \(P_5\), the path on five vertices from Unit 1. A cycle is a closed walk \(v_0, v_1, \ldots, v_k = v_0\) of length \(k \ge 3\) in which the vertices \(v_0, \ldots, v_{k-1}\) are all different, such as \(b, c, d, b\) in Figure 1(d); it is a copy of \(C_k\). The word “path” thus names both the subgraph \(P_5\) of Unit 1 and the sequence of its vertices in order, and the same holds for cycles. The order of the three notions is worth memorizing, since every path is a trail and every trail is a walk, whereas a walk need not be a trail and a trail need not be a path.
Walks are the convenient notion and paths are the interesting one. Walks are convenient because two of them can be joined: a walk from \(u\) to \(v\) followed by a walk from \(v\) to \(w\) is a walk from \(u\) to \(w\), whereas two paths joined together may revisit a vertex and stop being a path. Paths are what a traveller wants, and the next lemma says that nothing is lost by passing from one to the other.