Walks Paths and Connectedness
Walks and paths describe movement through a graph. They turn a static incidence object into a navigable structure: can we get from one vertex to another, how many edges are needed, and what breaks if a vertex or edge is removed? These questions are the language behind routing, social separation, network reliability, puzzle solving, and many graph algorithms.
Connectedness is the first global property most students meet. It is also the first place where local information can mislead: a graph may have many high-degree vertices and still be disconnected, while a sparse graph may be connected because its few edges are arranged efficiently. The central habit is to track actual routes, not just degree counts.
Definitions
A walk from to is an alternating sequence
where each edge joins to . In a simple graph we often abbreviate this as . The length of the walk is , the number of edges used, counted with repetition.
A trail is a walk with no repeated edge. A path is a walk with no repeated vertex. A closed walk begins and ends at the same vertex. A cycle is a closed walk of positive length with no repeated vertices except the initial/final vertex. In a simple graph, a cycle has length at least .
Vertices and are connected if there is a path from to . A graph is connected if every pair of vertices is connected. A component is a maximal connected subgraph. The distance is the length of a shortest path from to , and the diameter is the maximum distance between two vertices in a connected graph.
A bridge is an edge whose deletion increases the number of components. A cut vertex is a vertex whose deletion, together with its incident edges, increases the number of components. These are first measures of network vulnerability.
Key results
Walk-to-path reduction. If there is a walk from to , then there is a path from to .
Proof sketch: if a walk repeats a vertex, delete the closed portion between two occurrences of that vertex. The shorter sequence is still a walk from to . Repeating this process removes all repeated vertices.
Connectedness is an equivalence relation. On the vertex set of a graph, the relation "is connected to" is reflexive, symmetric, and transitive. Its equivalence classes are exactly the components of the graph.
Bridge characterization. An edge is a bridge if and only if lies on no cycle.
Proof sketch: if lies on a cycle, then deleting still leaves the rest of the cycle as a path from to , so no component is split. Conversely, if deleting does not disconnect its endpoints, there is a - path avoiding ; adding creates a cycle containing .
Minimum connected edge count. A connected graph on vertices has at least edges. Equality holds exactly for trees.
This is why paths and trees are the sparsest connected graphs: every extra edge beyond creates at least one cycle somewhere.
Component counting after deletion. If a graph has components and we delete an edge, the number of components either stays or becomes . It increases exactly when the deleted edge is a bridge inside its original component. Deleting a vertex can increase the component count by more than one, because all incident edges disappear at once.
This distinction matters in reliability questions. An edge bridge is a single failed connection that separates the network. A cut vertex is a failed station, router, or intersection that may remove many incident connections. A graph can have no bridges and still have cut vertices; two cycles sharing one common vertex are the standard example. Conversely, every bridge has endpoints whose removal may be important, but an endpoint of a bridge is not automatically a cut vertex when it is a leaf.
Blocks and local robustness. A maximal connected subgraph with no cut vertex is called a block. Introductory problems often avoid the full block-cut tree language, but the idea is useful: triangles and cycles provide local redundancy, while bridges stitch blocks together in a fragile way. When reading a drawing, first identify cyclic regions, then identify the bridge-like edges between them. This gives a fast mental map of the component structure after deletions.
Visual
The edge is a bridge because it is the only route from the left triangle to the right triangle. Removing or is also destructive, while removing a vertex inside either triangle leaves that local part connected.
| Object | Example in diagram | What happens when removed |
|---|---|---|
| Bridge | Graph splits into two components | |
| Non-bridge edge | Left side remains connected through | |
| Cut vertex | or | The bridge connection disappears |
| Non-cut vertex | The graph stays connected |
Worked example 1: Shortest paths and diameter
Problem. In the graph with edges
find and the diameter.
Method.
- Start from and list vertices by breadth-first layers.
- Layer : .
- Layer : vertices adjacent to , namely .
- Layer : vertices adjacent to layer that have not appeared. From we reach .
- Layer : from we reach .
Therefore the first time appears is layer , so
One shortest path is
To find the diameter, compute the largest shortest-path distance. The left triangle has internal distances , and the right triangle has internal distances . Distances crossing the bridge-like connection through are largest when we start at or and end at or . For example,
No distance can exceed because every vertex reaches within one step on the left, crosses in one step, and reaches any right vertex within one more step.
Checked answer. , and the diameter is .
Worked example 2: Identify bridges and components after deletion
Problem. Let have vertices and edges
Find all bridges and describe the components after deleting vertex .
Method.
- The edges form a triangle. None of them is a bridge.
- The edges form another triangle. None of them is a bridge.
- Edge joins the two cyclic blocks. It lies on no cycle, so it is a bridge.
- Edge is attached to the rest of the graph at vertex only. It lies on no cycle, so it is a bridge.
Thus the bridges are
Now delete vertex and all incident edges . The remaining edges are
The components are:
- The triangle on .
- The path on with edges .
Checked answer. The graph originally has two bridges, and . After deleting vertex , it has two components: and .
As a consistency check, notice that deleting the bridge alone would leave the triangle separated from the rest, while deleting alone would isolate vertex . Deleting vertex removes more structure: it deletes three incident edges at once, so it separates the left triangle from the path even though the edge remains.
Code
Breadth-first search gives components and shortest paths in unweighted graphs.
from collections import deque
def bfs_distances(adj, start):
dist = {start: 0}
q = deque([start])
while q:
u = q.popleft()
for v in adj[u]:
if v not in dist:
dist[v] = dist[u] + 1
q.append(v)
return dist
def components(adj):
unseen = set(adj)
parts = []
while unseen:
start = next(iter(unseen))
reached = set(bfs_distances(adj, start))
parts.append(reached)
unseen -= reached
return parts
adj = {
"A": {"B", "C"},
"B": {"A", "C"},
"C": {"A", "B", "D"},
"D": {"C", "E", "F"},
"E": {"D", "F"},
"F": {"D", "E"},
}
print(bfs_distances(adj, "A")["F"])
print(components(adj))
When solving connectedness problems by hand, mark layers or components directly on the drawing. A breadth-first layering gives distances from a start vertex; a component marking shows which vertices remain reachable after a deletion. This habit separates route-finding from guessing and makes it much easier to justify why a bridge or cut vertex really is unavoidable.
Common pitfalls
- Calling every repeated-edge route a path. A path cannot repeat vertices.
- Thinking a shortest walk might repeat a vertex. Repetition can be removed, so shortest walks are paths.
- Assuming a high minimum degree guarantees connectedness. Two disjoint cycles each have minimum degree but form a disconnected graph.
- Confusing bridges with cut vertices. Bridges are edges; cut vertices are vertices.
- Forgetting to delete all incident edges when removing a vertex.
- Treating distance as defined between vertices in different components. In finite graph theory it is usually undefined or infinite unless the graph is connected.