144. Directed graphs

144.1 About graphs in general

A graph is a mathematical construction that is used to encode information about connections between things. There are two main types of graphs, the kind called “undirected graph” in which only the connection between two things matters, and the kind called “directed graph” or “digraph” in which the direction of the connection matters. Each of these main types occurs in numerous subvarieties, only some of which are commonly used in computer science.

The terminology for different kinds of graphs in the literature is notoriously varied; it is probably true that if two graph theory books by different authors use the same terminology, one of the authors was the graduate student of the other one. The terminology in this text is similar to the usage in many (but not all) computer science books, but is quite different from that in books written by combinatorialists or graph theorists.

In this book, “graph” means undirected graph and “digraph” means directed graph. All graphs here are finite; although the definitions work for infinite graphs, many of the theorems are not true as stated for the infinite case.

144.1.1 Digraphs Informally, a digraph is a bunch of dots called nodes with arrows going from some nodes to others. Here are two examples.

Two digraphs: on the left nodes x, y, z, w with arrows a, b from x to y, c from z to x, d from x to z, e from z to y and a loop u at y; on the right nodes x, y, z with arrows a from y to x, b from x to y and c from x to z (144.1)

Here is a more precise definition:

144.2 Definition: directed graph

A directed graph or digraph $G$ consists of two finite sets $G_0$ and $G_1$ and two functions source$:G_1\to G_0$ and target$:G_1\to G_0$.

The elements of $G_0$ are called the nodes or vertices (singular: vertex) of $G$ and the elements of $G_1$ are the arrows or directed edges of $G$. If an arrow $a$ has source $x$ and target $y$ we write $a:x\to y$ in the same way we write functions.

144.2.1 Drawing digraphs A digraph $\langle G_0,G_1,s,t\rangle$ is conventionally drawn using dots or labels for the nodes, and an (actual) arrow going from node $x$ to node $y$ for each arrow $a$ (element of $G_1$) with source $x$ and target $y$.

144.2.2 Exercise Draw the following digraphs:

a) The graph with nodes $\{A,B,C,D\}$ and exactly one arrow from each node to $A$.

b) $G=(G_0,G_1,s,t)$ where $G_0=\{1,2,3\}$, $G_1=\{a,b,c,d,e\}$, $s(a)=s(e)=1$, $s(b)=s(c)=s(d)=2$, $t(a)=2$, $t(b)=t(c)=1$, and $t(d)=t(e)=3$. (Answer on page 251.)

144.2.3 Exercise Draw the graph $G_0=\{2,3,4,5,6,7,8,9,10\}$, with $n$ arrows going from $r$ to $s$ if and only if $r^n\mid s$ and $r^{n+1}$ does not divide $s$.

144.3 Definition: abstract description

The information about a digraph given by the definition, that is the sets $G_0$, $G_1$ and the source and target functions, is called the abstract description of the digraph.

144.3.1 Remark We will frequently encode the abstract description for a digraph as an ordered quadruple: thus “$G$ is the digraph $\langle G_0,G_1,s,t\rangle$” means $G_0$ is the set of nodes, $G_1$ the set of arrows, and $s$ and $t$ are the source and target functions.

144.3.2 Example The abstract description of the digraph on the left of Figure (144.1) has $G_0=\{x,y,z,w\}$, $G_1=\{a,b,c,d,e,u\}$,

$$\begin{aligned} \mathrm{source}(a)&=\mathrm{source}(b)=\mathrm{source}(d)=\mathrm{target}(c)=x \\ \mathrm{target}(a)&=\mathrm{target}(b)=\mathrm{target}(e)=\mathrm{source}(u)=\mathrm{target}(u)=y \end{aligned}$$

and $\mathrm{source}(c)=\mathrm{source}(e)=z$.

144.4 Graphs and abstraction

A digraph is defined here in an abstract way, not as a picture. The interplay between the abstract definitions and the pictures is analogous to that between the formula of a function such as $f(x)=x^2+1$ and its graph (a parabola) in analytic geometry. The pictures are more suggestive and comprehensible than the abstract definition, but it is difficult to prove things using pictures because it is hard to be sure you have the most general case. It may also be difficult or wasteful (or both) to store pictures directly in the computer. The abstract treatment is both more rigorous and more amenable to computation.

144.5 Digraphs in applications

144.5.1 Example Digraphs provide a natural way to encode data about certain kinds of complex systems. The flow chart of a program, for example, is a digraph. The commutative diagrams of sets and functions in Chapter 98 are examples of labeled digraphs. However, the information concerning the composites of the functions is additional information not encoded by the description of the diagrams as a digraph.

144.5.2 Example Digraphs are the natural way to model the sequencing of a collection of tasks that must be performed to accomplish a goal. Each node is a task and there is an arrow from task $a$ to task $b$ if task $a$ must be completed before task $b$ can be started. For example, the task of computing $\log(x^2+y^3)$ can be modeled this way:

Digraph from start to calculate x squared and to calculate y cubed, both to add, then add to calculate log (144.2)

This graph shows, for example, that if you had two people or two processors to perform the squaring you could speed up the computation. Digraphs arising in this way often have a weight function on the arrows.

144.5.3 Exercise Draw the digraph modeling the computation of the truth value of the equation

$$x^2+xy^2=x^2-y$$

Pages 218–220 of the book (PDF).