A path in $G$ is a sequence of vertices $v_0, v_1, \ldots, v_k$ where $(v_i, v_{i+1})\in E$ for each $0\leq i< k$.
Example paths
Simple path (no $v_i$ repeated): $c, a, b$
Cycle ($v_0=v_k$): $b, a, a, a, b$
Simple cycle ($v_0=v_k$ and no other $v_i$ repeated): $b, a, b$
We’ve defined paths on graphs but the same definition
applies to relations, since a relation and its
graph representation are interchangeable.
Relational composition using directed graphs
If $R$ and $S$ are relations on $A$, compute $R\circ S$ as follows:
Create the digraph $G = (A, R\cup S)$.
Add an edge $(a,b)$ to $R\circ S$ iff there is a path $a,v,b$ in $G$ such that $(a,v)\in R$ and $(v, b)\in S$.
Example:
$R=\{(1,2), (2,1), (1,3)\}$
$S=\{(2, 2), (2, 3), (3, 1)\}$
$G = (\{1,2,3\}, R\cup S)$
$R\circ S$
Powers of a relation using directed graphs
Length of a path in a graph
The length of a path $v_0, \ldots, v_k$ is the number of edges in it, i.e., $k$.
Powers and paths
Let $R$ be a relation on a set $A$.
There is a path of length $n$ from $a$ to $b$ in $R$
if and only if $(a, b)\in R^n$.
Reflexive transitive closure using directed graphs
Connectivity relation
Let $R$ be a relation on a set $A$. The connectivity relation $R^\star$ consists
of the tuples $(a,b)$ such that there is a path (of any length) from $a$ to $b$ in $R$.
Connectivity and reflexive transitive closure
The reflexive transitive closure $R^* $ of a relation $R$ is its connectivity relation $R^\star$,
i.e., $R^\star = R^* = \bigcup_{n=0}^\infty R^n$.
Summary
Relations are a fundamental structure in computer science.
A relation is a set of tuples.
Relations can be reflexive, (anti)symmetric, transitive.
We can combine binary relations with the composition $\circ$ operator.
Directed graphs consist of nodes and edges (ordered pairs of nodes).
Relations can be represented as directed graphs.
The two representations are interchangeable: relational operations have corresponding graph operations and vice versa.