Paths and Cycles
Walks, paths, when they loop
A path is a sequence of vertices you can traverse by following edges. It is
how we talk about moving through a graph.
Definition 6.2.1 (notes p. 90): A path in is an
-tuple
such that for every , with .
The vertex is the start and is the end; the number is the
length of the path. Note: not all need to be different! When they are
distinct, the path is simple.
Three nested concepts:
- A walk allows repeated vertices and edges.
- A trail allows repeated vertices but distinct edges.
- A path has distinct vertices (and therefore distinct edges).
Definition 6.2.2 (notes p. 90): A path is cyclic (a cycle) if
. A cycle is simple if no other vertex repeats.
Cycles cause real problems. Even a tiny cyclic graph can have paths of infinite
length — you just go around the cycle forever. This is why acyclic graphs are
often the focus in AI: parse trees, search trees, dependency graphs, causal graphs.
The length of a path matters: in a knowledge graph, a 1-hop path is a direct
relation; a 2-hop path is a relation-of-a-relation ("Paris", "capital-of", "France",
"speaks", "French"). The number of hops is a measure of how indirect the inference is.
- 0.0sEuler tours and the Konigsberg bridges
- 1.3sFour vertices: left bank, right bank, islands A and B
- 2.5sSeven amber bridges draw between them
- 4.6sA violet walker starts at the left bank
- 5.2sWalker traverses bridges one by one, lighting them green
- 7.4sWalker gets stuck: stuck label appears in red
- 8.2sRed degree labels: LB 3, RB 3, A 5, B 3
- 9.8sAll odd-degree vertices — no Eulerian trail exists
- 11.0sThe original Konigsberg puzzle has no solution
Definition 2.5 (depth of a vertex). Let be a directed graph. The depth of a vertex is the length of the longest directed path that starts at :
If no path starts at (i.e. is a sink), . If there are arbitrarily long paths starting at , .
Definition 2.6 (depth of a graph). The depth of a graph is the supremum over all vertices:
Example 2.7. Consider the path graph with edges :
- (we can walk forever to the right).
- for every — there is always a longer path to the right.
- .
For a finite acyclic graph (DAG), every vertex has finite depth and is bounded by the length of the longest path.