Following Arcs in a Directed Graph
In an undirected graph, an edge can be followed in either direction. In a digraph, each arc has a specified direction, so a sequence of adjacent vertices is useful only when every step follows its arc in the forward direction. This distinction matters when asking which vertices can be reached from a starting point: two vertices may be connected by an arc in one direction without being reachable from one another.
Throughout, a digraph is finite, has no loops or parallel arcs, and may contain both arcs \(uv\) and \(vu\). Write \(uv\) for the arc directed from \(u\) to \(v\). A sequence of vertices follows a directed route only when each consecutive pair is an arc in the listed direction.
Thus, every directed path is a directed trail and every directed trail is a directed walk, but the reverse implications need not hold. The length is the number of arcs traversed, not the number of listed vertices. A walk may return to its starting vertex; that does not make it a path unless it has length zero.
Worked Example: Walk, Trail and Path
Let \(G\) be the digraph with vertex set \(V(G)=\{a,b,c,d\}\) and arc set \(E(G)=\{ab,bc,ca,ad,da\}\). Consider the following sequences.
The sequence \(a,b,c,a,d\) follows the arcs \(ab,bc,ca,ad\), so it is a directed walk of length \(4\). No arc is repeated, so it is also a directed trail. But the vertex \(a\) occurs twice, so it is not a directed path.
The sequence \(a,b,c,a,b\) follows \(ab,bc,ca,ab\). It is a directed walk of length \(4\), but not a trail because the arc \(ab\) is used twice. It is not a path either, since \(a\) and \(b\) both repeat.
The sequence \(a,d\) follows the single arc \(ad\). Its vertices are distinct, so it is a directed path and a directed trail of length \(1\). The sequence \(c,c\) is not a walk of length \(1\), because there is no loop \(cc\); the length-zero path at \(c\) is instead written as the one-vertex sequence \(c\).
Check: Each consecutive pair in the first two sequences is in the stated arc set. The repeated-arc test rules out a trail for the second sequence, while the repeated-vertex test rules out a path for both longer sequences.
Reachability
Including the length-zero path makes reachability reflexive: \(u\in R(u)\) for every vertex \(u\). Reachability follows arc direction, and it need not be symmetric. For example, the arc \(uv\) gives a path from \(u\) to \(v\), but by itself gives no path from \(v\) to \(u\).
Proof. Among all directed walks from \(u\) to \(v\), choose one of minimum length; such a minimum exists because the lengths are nonnegative integers and the set of possible lengths is nonempty. Write it as \(v_0,v_1,\ldots,v_\ell\). If a vertex repeats, then \(v_i=v_j\) for some \(0\le i<j\le\ell\). Delete the portion \(v_i,v_{i+1},\ldots,v_j\), retaining \(v_i\) and continuing with \(v_{j+1}\) if \(j<\ell\). This is still a directed walk: when \(j<\ell\), the required next arc is \(v_jv_{j+1}\), and \(v_i=v_j\), so that same arc goes from \(v_i\) to \(v_{j+1}\). If \(j=\ell\), then \(v_i=v_\ell=v\), so the shortened sequence still ends at \(v\). In either case the endpoints are unchanged and the length decreases by \(j-i>0\), contradicting minimality. Thus the minimum-length walk has no repeated vertices and is a path. When \(u=v\), the length-zero path already gives the conclusion. \(\square\)
This lemma means that reachability can equivalently be tested by asking whether any directed walk exists. It also shows why repeated vertices in a route do not create new reachable endpoints: a section that leaves a vertex and later returns to it can be removed.
Proof. Take a directed path from \(u\) to \(v\) and a directed path from \(v\) to \(w\). Follow the first path and then the second. The result is a directed walk from \(u\) to \(w\), because both sequences meet at \(v\) and every step follows an arc. By the Lemma, a directed walk from \(u\) to \(w\) contains a directed path with the same endpoints. Therefore \(w\) is reachable from \(u\). The argument also covers length-zero paths when \(u=v\) or \(v=w\). \(\square\)
Worked Example: Reachability Depends on Direction
Let \(G\) have vertex set \(V(G)=\{1,2,3,4,5\}\) and arc set \(E(G)=\{12,23,32,34,54\}\). The arcs \(23\) and \(32\) form a two-way connection between \(2\) and \(3\), but the other arcs do not point both ways.
Starting at \(2\), the length-zero path reaches \(2\), the arc \(23\) reaches \(3\), and the sequence \(2,3,4\) reaches \(4\). No arc leaves \(4\), so there is no route from \(2\) to \(1\) or \(5\). Therefore \(R(2)=\{2,3,4\}\).
Starting at \(4\), only the length-zero path is available, so \(R(4)=\{4\}\). Starting at \(5\), the length-zero path reaches \(5\), and the arc \(54\) reaches \(4\); again there is no arc leaving \(4\), so \(R(5)=\{4,5\}\).
Check: The sequence \(5,4\) is a directed path, but \(4,5\) is not a directed walk because \(45\notin E(G)\). Similarly, \(2,3,4\) is a path, but the arc \(12\) cannot be used backwards to reach \(1\) from \(2\).
Finding a Reachable Set by Breadth-First Search
For a finite digraph, breadth-first search (BFS) systematically explores outward from a chosen start vertex \(s\). It stores discovered vertices in a queue, a list in which the earliest inserted vertex is processed first. Give \(s\) distance label \(0\). Whenever a vertex with label \(k\) is processed, inspect each arc leaving it; any undiscovered endpoint receives label \(k+1\) and is added to the back of the queue. Record the arc by which each vertex was first discovered as its predecessor arc. Stop when the queue is empty.
Proof. First, every discovered vertex is reachable: \(s\) is reachable by the length-zero path, and each later discovery follows an arc from a vertex already known to be reachable. Appending that arc to a path to the earlier vertex gives a directed walk; the Lemma supplies a path to the newly discovered vertex.
Now consider any vertex \(v\) reachable from \(s\), and take a shortest directed path \(s=v_0,v_1,\ldots,v_k=v\). We show in order along this path that BFS discovers each \(v_i\). It starts with \(v_0=s\). If \(v_i\) is discovered, it is eventually processed because the graph is finite and the queue continues until empty. When it is processed, the arc \(v_iv_{i+1}\) is inspected. The endpoint \(v_{i+1}\) is then either already discovered or is added to the queue. Thus \(v\) is discovered. This proves that the discovered set is exactly \(R(s)\).
For the distance claim, a vertex assigned label \(k\) has a predecessor chain of \(k\) arcs back to \(s\), so there is a path of length \(k\). To see that no shorter path exists, suppose a path of length \(j\) reaches a vertex \(v\). Its vertices occur in order along the path. Starting with \(s\) at label \(0\), each arc can lead to a discovery at most one level later; processing vertices in queue order ensures every vertex at a smaller label is processed before one at a larger label. Following the path therefore shows that \(v\) is discovered with label at most \(j\). Taking \(j\) to be the shortest possible path length shows the BFS label is no greater than that distance. Combined with the predecessor path of length equal to the label, the label is exactly the shortest distance. \(\square\)
Worked Example: BFS from a Starting Vertex
Let \(G\) have vertex set \(V(G)=\{a,b,c,d,e,f,g,h\}\) and arc set \(E(G)=\{ab,ac,bd,ce,de,ed,df,fg\}\). Run BFS from \(a\). In the table, the queue is shown before and after processing each vertex.
| Processed | Queue before | New discoveries | Queue after |
|---|---|---|---|
| \(a\) | \([a]\) | \(b(1),c(1)\) | \([b,c]\) |
| \(b\) | \([b,c]\) | \(d(2)\) | \([c,d]\) |
| \(c\) | \([c,d]\) | \(e(2)\) | \([d,e]\) |
| \(d\) | \([d,e]\) | \(f(3)\) | \([e,f]\) |
| \(e\) | \([e,f]\) | None; \(d\) is already discovered | \([f]\) |
| \(f\) | \([f]\) | \(g(4)\) | \([g]\) |
| \(g\) | \([g]\) | None | \([]\) |
The labels are \(a:0\), \(b:1\), \(c:1\), \(d:2\), \(e:2\), \(f:3\), and \(g:4\). For example, the predecessor arcs give the paths \(a,b,d\) to \(d\), \(a,c,e\) to \(e\), and \(a,b,d,f,g\) to \(g\). Vertex \(h\) is never discovered, so \(R(a)=\{a,b,c,d,e,f,g\}\).
Check: Every vertex in the listed set has a displayed predecessor path from \(a\). The only arc into \(h\) would have to appear in the arc set, but none does; hence no directed path from \(a\) can end at \(h\). The discovered distances agree with shortest paths: \(b,c\) require one arc, \(d,e\) require two, \(f\) requires three, and \(g\) requires four.
Common Pitfalls and Uses
Wrong calculation: In the preceding digraph, one might treat \(ab\) as if it also allowed travel from \(b\) to \(a\), then claim \(a\in R(b)\). That reverses the arc: \(ab\) means \(a\) to \(b\), not \(b\) to \(a\). Checking the actual outgoing arcs from \(b\), only \(bd\) leaves \(b\); in fact \(R(b)=\{b,d,e,f,g\}\), using \(b,d,e\) and \(b,d,f,g\) as paths where needed. More precisely, \(b\) reaches \(d\), then \(e\) and \(f\), and then \(g\); it does not reach \(a,c,\) or \(h\). The correction is to follow only arcs whose tails are at vertices already reached.
Reachability is a basic way to describe what can be accessed from a starting state, location or task when transitions have direction. In computation, BFS finds the reachable set and shortest path lengths in a finite unweighted digraph. It can also provide an actual route: tracing predecessor arcs backward from a discovered vertex, then reversing that list, gives a directed path from the start.
Keep the three questions separate: a walk allows repeated vertices and arcs; a trail forbids repeated arcs; a path forbids repeated vertices. Reachability asks whether at least one path exists, not how many walks there are. In particular, cycles can create arbitrarily long walks without changing which vertices are reachable.
Check Your Understanding
For each question, pay attention to the direction of every arc and whether a length-zero path is allowed.
- In a digraph with arcs \(pq,qr,rp\), is \(p,q,r,p\) a walk, a trail, or a path? Give its length.
- Let \(V=\{1,2,3,4\}\) and \(E=\{12,23,34\}\). Find \(R(2)\) and \(R(4)\).
- Explain why every directed path is a directed trail, but not every directed trail is a directed path.
- Give a proof that if \(v\in R(u)\) and \(w\in R(v)\), then \(w\in R(u)\).
- Run BFS from \(x\) when \(V=\{x,y,z,w\}\) and \(E=\{xy,xz,yw,zw\}\). Give each vertex's label and the reachable set.