INAIO Guide Stage 1 12Graph Theory and Algorithms
12.2 Paths, cycles and connectivity
Follow edges to decide whether a route exists, whether it loops, and which vertices are connected.
Once a graph records connections, we can ask whether one vertex can be reached from another. A route may stop at a target, return to its start, or fail because an arrow points the wrong way. These distinctions matter in travel networks, task dependencies, and information flow.
This is foundational to intermediate graph theory. Read graph representations first. MIT OpenCourseWare's Mathematics for Computer Science has chapters on undirected and directed graphs.
A basic idea: follow the arrows
Suppose the graph has , , , and . From you can reach along . From you cannot return: it has no outgoing edge. The first three vertices form a directed cycle, but is outside it.
A quick tour of route words
A walk follows adjacent edges and may repeat vertices. In this module, a path is a walk with no repeated vertices. A cycle starts and ends at the same vertex and otherwise does not repeat vertices. A length-zero path lets a vertex reach itself. Stating these conventions matters because textbooks sometimes use “path” more broadly.
In an undirected graph, vertices are connected if a path joins them; the graph is connected if every pair is connected. A connected component is a largest connected group. In a directed graph, reachability is ordered: may reach even when cannot reach . Two vertices are strongly connected if each reaches the other. If we ignore arrow directions and the graph becomes connected, it is weakly connected.
Cycles can be helpful or harmful depending on the meaning of the edges. A road loop offers another route. A cycle of “must finish before” prerequisites is impossible to satisfy without changing the rules. Module 12.5 groups mutually reachable vertices into strongly connected components.
Application 1: prerequisites
Tasks have arrows , , and , meaning the task at the arrow's tail must precede the one at its head. Can lead to ? Can lead back to ?
- Trace forward. is a path, so is reachable from .
- Check reverse edges. No edge leaves , so is not reachable from .
- Check for cycles. This graph has none. Adding would create , a contradictory prerequisite loop.
Application 2: disconnected roads
Two-way roads join to and to . Town has no road. How many connected components are there, and what changes if a road joins and ?
- Group reachable towns. reach one another through roads; reaches only itself.
- Count components. There are two: and .
- Add the new road. – connects the groups, leaving one connected component.
Because these roads are two-way, a route works in reverse as well.
Resources
| Source | Title | Why read it |
|---|---|---|
| MIT OpenCourseWare | Mathematics for Computer Science | Read the graph and directed-graph chapters for paths, cycles, and connectivity. |
Finished this module? Mark it done.
Comments
Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.
Loading comments