Skip to content
Part IA Michaelmas, Lent Term

Directed Graphs, Paths, and Reachability

Directed Graphs

Definition

A directed graph (or digraph) is a pair (V,E)(V, E) where:

  • VV is a set of vertices (or nodes)
  • EV×VE \subseteq V \times V is a set of edges (or arcs)

Note: A digraph is exactly an endo-relation E:VVE : V \nrightarrow V.

Visualisation

Draw each vertex as a point. Draw an arrow from vv to ww iff (v,w)E(v, w) \in E.

A directed graph with 4 vertices

Paths

Definition

A path (or walk) in a digraph is a sequence v0,v1,,vkv_0, v_1, \ldots, v_k such that (vi1,vi)E(v_{i-1}, v_i) \in E for each i=1,,ki = 1, \ldots, k.

  • The length of the path is kk (the number of edges)
  • A simple path visits no vertex twice
  • A cycle is a path from a vertex back to itself

Path Relation

The path relation EE^{\circ *} relates vv to ww iff there exists a path from vv to ww:

E=n0EnE^{\circ *} = \bigcup_{n \geq 0} E^{\circ n}

where EnE^{\circ n} is the nn-fold composite.

Reachability

Definition

Vertex ww is reachable from vertex vv if there is a path from vv to ww.

Equivalently: vEwv E^{\circ *} w.

Computing Reachability

For an nn-vertex graph, any simple path has length <n< n. Therefore:

E=k=0n1EkE^{\circ *} = \bigcup_{k=0}^{n-1} E^{\circ k}

This gives an algorithm: compute IEE2En1I \cup E \cup E^2 \cup \cdots \cup E^{n-1}.

Adjacency Matrix Approach

Let MM be the adjacency matrix. Compute:

M=IMM2Mn1M^* = I \oplus M \oplus M^2 \oplus \cdots \oplus M^{n-1}

Then Mij=1M^*_{ij} = 1 iff jj is reachable from ii.

Preorders

Definition

A relation RR on AA is a preorder if it is:

  1. Reflexive: a.aRa\forall a. aRa
  2. Transitive: a,b,c.(aRbbRcaRc)\forall a, b, c. (aRb \land bRc \Rightarrow aRc)

A preorder is a partial order if it is also antisymmetric: (aRbbRa)a=b(aRb \land bRa) \Rightarrow a = b.

Examples

RelationType
\leq on R\mathbb{R}Partial order
\subseteq on P(X)\mathcal{P}(X)Partial order
\mid (divisibility) on Z+\mathbb{Z}^+Partial order
\mid on Z\mathbb{Z}Preorder (not antisymmetric: 11-1 \mid 1 and 111 \mid -1)
Reachability in a digraphPreorder

Reflexive-Transitive Closure

Definition

The reflexive-transitive closure of RR is the smallest preorder containing RR:

R={P:RP,P is a preorder}R^{\circ *} = \bigcap \{P : R \subseteq P, P \text{ is a preorder}\}

Examinable Proof: Characterisation

Theorem: RR^{\circ *} is the smallest preorder containing RR.

Proof:

Part 1: RR^{\circ *} is a preorder containing RR.

  • RRR \subseteq R^{\circ *}: R1=RR^{\circ 1} = R, and R=n0RnR^{\circ *} = \bigcup_{n \geq 0} R^{\circ n}.
  • Reflexivity: R0=idRR^{\circ 0} = \text{id} \subseteq R^{\circ *}.
  • Transitivity: If aRba R^{\circ *} b and bRcb R^{\circ *} c, there exist paths from aa to bb and bb to cc. Concatenating gives a path from aa to cc.

Part 2: RR^{\circ *} is the smallest such preorder.

Let PP be any preorder with RPR \subseteq P. We show RPR^{\circ *} \subseteq P.

By induction on nn: RnPR^{\circ n} \subseteq P for all nn.

  • Base (n=0n = 0): R0=idPR^{\circ 0} = \text{id} \subseteq P by reflexivity.
  • Step: R(n+1)=RRnPP=PR^{\circ (n+1)} = R \circ R^{\circ n} \subseteq P \circ P = P by transitivity.

Thus nRnP\bigcup_n R^{\circ n} \subseteq P.

Transitive Closure

The transitive closure R+=n1RnR^{\circ +} = \bigcup_{n \geq 1} R^{\circ n} is the smallest transitive relation containing RR.


Summary

  • A digraph (V,E)(V, E) is an endo-relation E:VVE : V \nrightarrow V
  • Path relation EE^{\circ *} relates connected vertices
  • RR^{\circ *} is the reflexive-transitive closure: smallest preorder containing RR
  • Reachability computed via matrix powers MM^* up to Mn1M^{n-1}