Discord

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 A→BA\to B, B→CB\to C, C→AC\to A, and C→DC\to D. From AA you can reach DD along A→B→C→DA\to B\to C\to D. From DD you cannot return: it has no outgoing edge. The first three vertices form a directed cycle, but DD is outside it.

A directed cycle A to B to C to A, with one arrow from C to D. A route from A to D is highlighted, while D has no route back.A directed cycle A to B to C to A, with one arrow from C to D. A route from A to D is highlighted, while D has no route back.
One-way reachability does not imply a route in the reverse direction.

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: uu may reach vv even when vv cannot reach uu. 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 A→BA\to B, B→CB\to C, and A→DA\to D, meaning the task at the arrow's tail must precede the one at its head. Can AA lead to CC? Can CC lead back to AA?

  1. Trace forward. A→B→CA\to B\to C is a path, so CC is reachable from AA.
  2. Check reverse edges. No edge leaves CC, so AA is not reachable from CC.
  3. Check for cycles. This graph has none. Adding C→AC\to A would create A→B→C→AA\to B\to C\to A, a contradictory prerequisite loop.

Application 2: disconnected roads

Two-way roads join PP to QQ and QQ to RR. Town SS has no road. How many connected components are there, and what changes if a road joins RR and SS?

  1. Group reachable towns. P,Q,RP,Q,R reach one another through roads; SS reaches only itself.
  2. Count components. There are two: {P,Q,R}\{P,Q,R\} and {S}\{S\}.
  3. Add the new road. RR–SS connects the groups, leaving one connected component.

Because these roads are two-way, a route works in reverse as well.

Resources

SourceTitleWhy read it
MIT OpenCourseWareMathematics for Computer ScienceRead 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