Module Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

MA32410 - GRAPHS AND NETWORKS

DR. GWION EVANS

1. Graphs and Digraphs


Definition 1.1. A graph G is an orderd pair (V (G), E(G)), where V = V (G) is a
finite non-empty set of objects called the vertices of G, and E = E(G) is a finite list of
unordered pairs of vertices called edges.
Remarks 1.2. (1) Edges of a graph G are subsets of V (G) consisting of exactly one or
two elements.
(2) The edge list E is not formally a set since an edge e can appear in the list more
than once, in which case it is called a multiple edge and the number of times it
appears is called the multiplicity of e.
(3) G is sometimes referred to as an undirected graph to emphasise that the pairs
of vertices forming an edge are unordered (cf. later, where directed graphs are
defined).
Notation 1.3. We write e = uv if e is an edge of G consisting of the vertices u and
v, called the end vertices of e, and say that e is the edge joining u and v or that e is
incident with u (or v). [WARNING: the notation e = uv is useful but may be ambiguous
if e is a multiple edge.]
If u, v ∈ V and uv is an edge, we say that u and v are adjacent vertices. Sometimes
geometric jargon such as ‘e is on u’ is used to mean that the vertex u is an end vertex of
the edge e.
We shall abuse notation slightly by writing e ∈ E to mean ’e is an edge of G’.
We can picture graphs by drawing a dot for each vertex and a curve joining vertices
u and v for an edge incident with both u and v. For example, if V = {a, b, c} and
E = {aa, ab, ab, ac, ac, bc} then we draw:
b

c
a

Definition 1.4. A simple graph is a graph with no multiple edges or loops.


If we replace unordered by ordered in the definition of a graph we have the definition
of a directed graph (or digraph).
Definition 1.5. A directed graph (or digraph) G is an ordered pair (V (G), E(G)),
where V = V (G) is a finite non-empty set of objects called the vertices of G, and
E = E(G) is a finite list of ordered pairs of vertices called edges.
Date: January 29, 2024.
The author is indebted to Professor Vassilis C Mavron for sharing his lecture notes, on which these
notes are based.
1
2 DR. GWION EVANS

Remarks 1.6. (1) The notation and terminology for digraphs is much the same for
graphs but with obvious variations.
(2) Edges of a digraph G are elements of V (G) × V (G), i.e., they are ordered pairs
of vertices. Note the edge e = (u, v) has end vertices u and v. We can still write
e = uv but now vu may not be an edge, but even if it is uv ̸= vu (unless v = u).
(3) We say that the edge u = uv is in the direction u to v or e is from (or out of ) u
to (or into v).
Definition 1.7. A simple digraph is a digraph with no multiple edges or loops. That
is, an edge uv ∈ E appears only once in E (though vu may be an edge) and there are no
edges of the form uu.
Remark 1.8. In this course the term graph always means undirected graph. Some
texts differ and use the term graph to cover both directed and undirected graphs. Notation
and terminology in graph theory is not fully standardized. For instance, the terms node
and arc are sometimes used for vertex and edge, respectively.
Definition 1.9. Two graphs (or digraphs) G = (V, E) and G′ = (V ′ , E ′ ) are isomorphic
if there is a bijection ϕ : V → V ′ such that uv ∈ E iff ϕ(u)ϕ(v) ∈ E ′ , and uv and
ϕ(u)ϕ(v) have the same multiplicity in G and G′ , respectively. In this case, ϕ is called an
isomorphism. If in addition G = G′ then we say that ϕ is an automorphism.
Remark 1.10. We will frequently consider isomorphic graphs as being equal.
Definitions 1.11. (1) In a graph G, the degree δ(u) of a vertex u is the number
of edges incident with u (i.e., the number of edges of which u is an end vertex),
with the proviso that a loop on u is counted as being incident twice with u and
therefore contributes 2 to the degree of u. We shall say that a vertex is odd
(even) if its degree is odd (even).
(2) A graph G is regular of degree r if every vertex of G has degree r. We say that
G is regular if it is regular of degree r for some r.
(3) A vertex is isolated if its degree is zero.
(4) In a digraph, we define the out-degree δ(u) as the number of edges out of u. The
in-degree δ(u) is the number of edges into u. (Note that each loop on a vertex u
contributes its multiplicity to each of δ(u) and δ(u)).
There is a natural choice of graph to associate with a given digraph. We can also
associate a digraph with a given graph, but we need to take some care.
Definitions 1.12. (1) The underlying graph (UG), of a digraph is obtained by
ignoring the directions of edges.
(2) From any graph G we can form a digraph G′ by replacing each edge uv of G by
two directed edges uv and vu. Whenever we say ‘a graph can be considered
as a digraph’, this is what we mean.
Remarks 1.13. (1) The degree of a vertex in the UG is the sum of its out-degree and
in degree in the digraph.
(2) If u is a vertex of degree d in G, then the vertex u has out-degree d and in-degree
d in G′ .
(3) The number of edges in G′ is twice that in G.
Notation 1.14. If G = (V, E) is a graph or digraph, the number of vertices in G is
denoted by |V | and the number of edges by |E|.
P P
Theorem 1.15. If G = (V, E) is a digraph, then v∈V δ(v) = v∈V δ(v) = |E|.
MA32410 - GRAPHS AND NETWORKS 3

Proof. (To be revealed). □


Corollary 1.16. The sum of the vertex degrees in any graph is twice the number of edges.
Proof. (To be revealed). □
Corollary 1.17. The number of vertices of odd degree in a graph is even.
Proof. (To be revealed). □

2. Some Special Graphs

(1) The complete graph Kn on n vertices is the simple graph in which every pair
of distinct vertices is an edge.

K1 K2 K3 K4

(2) The null graph Nn on n vertices is the graph with n vertices and no edges.

N1 N2 N3 N4

(3) A bipartite graph G is a graph whose vertices can be partitioned into two non-
empty sets, A and B say, called the parts, such that every edge has one vertex
in A and the other vertex is in B. That is, no two vertices in A are adjacent, and
similarly for B. The example below has |A| = 4 and |B| = 3 (note that one vertex
in part A has degree zero – not every vertex must be incident with an edge).

(4) The complete bipartite graph Km,n is the simple bipartite graph with parts A
and B such that |A| = m, |B| = n and every pair of vertices with a vertex in A
and a vertex in B is an edge. For example,
A

K1,1 K3,2 K2,4

(5) The complete digraph on n vertices is the simple digraph in which every
ordered pair of distinct vertices is an edge. The cases n = 1, 2, 3 are drawn below:
4 DR. GWION EVANS

(6) A digraph is bipartite if its UG is bipartite.


(7) A graph is said to be planar if it has a diagram in the plane that has no crossing
edges, i.e., edges intersect at vertices only.
(8) The complement G of a simple graph G is the graph with the same vertex set
as G and in which adjacency is defined by non-adjacency in G. That is, a pair of
vertices is an edge in G if it is not an edge in G. Examples: (i) the complement
of G is G; (ii) Kn is the complement of Nn , and vice versa.

3. Subgraphs and Paths


Definition 3.1. A graph (or digraph) H is a subgraph of a graph (or digraph) G if H
can be obtained by deleting vertices or edges from G, where deleting a vertex also means
deleting all edges incident with it.
Remarks 3.2. (1) We regard G as a (trivial) subgraph of itself.
(2) Any vertex of G is, by itself, a (trivial) subgraph of G.
Definition 3.3. A subgraph H of G is spanning if it has the same vertices as G.
Remarks 3.4. (1) Any simple graph with m vertices can be regarded as a subgraph of
Kn for all n ≥ m (it is a spanning subgraph if m = n).
(2) The null graph Nm can be regarded as a subgraph of any graph with n vertices,
for all n ≥ m (it is a spanning subgraph if m = n).
Definition 3.5. A walk of length m ≥ 1 in a digraph G is a sequence of m edges (not
necessarily distinct)
e1 e2 · · · em
such that the end vertex of each edge is the start vertex of the next edge. A walk of
length 0 is a single vertex. The walk is closed if it is of zero length or the end vertex of
the last edge is the start vertex of the first edge; otherwise the walk is open. The edges
ei are the edges of the walk and the vertices of the walk are the vertices incident
with these edges.
If G is a simple digraph, the walk can be specified by the sequence of (not necessarily
distinct) vertices
v0 v1 · · · vm
where ei = vi−1 vi for i = 1, . . . , m.
Definition 3.6. For a graph G, a walk of length m is an alternating vertex-edge sequence
u0 e1 u1 e2 · · · um−1 em um
where ui−1 and ui are the end vertices of ei , for i = 1, 2, . . . , m. (A walk of length 0
consists of just one vertex.) The walk is closed if u0 = um .
If the graph G is simple, as for digraphs, there is no ambiguity in specifying the walk
by the sequence of its vertices
u0 u1 · · · um .
Definitions 3.7. In a graph or digraph:
(1) A walk is a trail if all its edges are different. A closed trail is called a circuit
MA32410 - GRAPHS AND NETWORKS 5

(2) A trail is a path if all its vertices are different, except that we allow the first and
last vertices to be the same if the path is closed.
Remark 3.8. In a graph or digraph, a walk from a vertex u to a vertex v with distinct
vertices (except that we allow u = v if the path is closed) is necessarily a trail and therefore
a path (and therefore a cycle if it is closed).
Definition 3.9. A closed path of length r ≥ 1 in a graph or digraph is called a cycle or
an r-cycle.
Definitions 3.10. (1) In a graph, two vertices u and v are connected if u = v or
there is a walk connecting u and v.
(2) A connected graph is a graph in which any two vertices are connected.
(3) A connected digraph is a digraph whose UG is connected.
(4) A strongly connected digraph is a digraph in which there is a walk from any
given vertex u to any other distinct vertex.
Definition 3.11. A component C of a graph G is a subgraph of G satisfying:
(1) C is a connected graph; and
(2) if H is a connected subgraph of G such that C is a subgraph of H then H = C.
Remark 3.12. (1) A component, being itself a graph, must contain at least one vertex.
(2) A component is a maximally connected subgraph.
Theorem 3.13. Let G be a graph.
(1) The components of G partition G (i.e., each vertex and each edge are in exactly
one component).
(2) Any walk forms a subgraph of some component of G.
(3) G is connected if and only if G has only one component.
Proof. (To be revealed). □
Theorem 3.14. In a graph or digraph that has exactly n vertices, the length of any path
is at most n − 1, except that if the path is closed (and therefore a cycle) its length is at
most n.
Proof. (To be revealed). □
As the next theorem confirms, we may replace walk with path in the definition of two
vertices being connected.
Theorem 3.15. In a graph or digraph, if there is a walk from a vertex u to another vertex
v (u ̸= v) then there is a path from u to v.
Proof. (To be revealed). □
Definition 3.16. Consider a walk u0 e1 u1 · · · em um in a graph. The walk is said to
be backtracking if ei = ei+1 for some 1 ≤ i < m, otherwise the walk is said to be
non-backtracking.
A walk of length zero in a graph or digraph is called a trivial closed walk.
Theorem 3.17.
(1) A digraph that contains a non-trivial closed walk contains a cycle.
(2) A graph that contains a non-trivial non-backtracking closed walk contains a cycle.
Proof. (To be revealed). □
Corollary 3.18. If a graph or digraph has a non-trivial circuit, then it contains a cycle.
6 DR. GWION EVANS

Proof. (To be revealed). □

Corollary 3.19. If a digraph is strongly connected and has more than one vertex, then
every vertex is on a cycle.

Proof. (To be revealed). □

4. Graphs and Matrices


Let G = (V, E) be a graph or digraph with V = {u1 , u2 , . . . , un }. The adjacency
matrix of G is the n × n matrix A defined by:

0
 if ui uj is not an edge,
Aij = the multiplicity of ui uj otherwise.

(counting each loop twice if G is a graph)

Properties of the adjacency matrix A of a graph


(1) A is symmetric; P
(2) for each i, δ(ui ) = nj=1 Aij = nj=1 Aji ; and
P

(3) if the graph is simple then A then it has zeros on the diagonal and its only entries
are 0 or 1.
Properties of the adjacency matrix A of a digraph
(1) A is not necessarilyPsymmetric;
(2) for each i, δ(ui ) = nj=1 Aij ; δ(ui ) = nj=1 Aji .
P

(3) if the digraph is simple then A then it has zeros on the diagonal and its only
entries are 0 or 1.

Theorem 4.1. Let G = (V, E) be a digraph with exactly m vertices u1 , . . . , um , and let
A be its adjacency matrix. For any integer r ≥ 1, Arij is the number of walks of length r
from ui to uj .

Proof. (To be revealed). □

The Adjacency Matrix Row Algorithm (also known as the Fusion Algorithm).
The algorithm below finds components of a graph. Let A be the adjacency matrix of a
graph G = (V, E) and let u1 , u2 , . . . , un be the vertices of G. There is no loss of generality
in our assuming that G is simple.
In what follows, we will use so-called Boolean addition: all non-zero positive integers
are considered to be equal to 1 so that 1 + 1 = 1, 1 + 0 = 1, 0 + 0 = 0.
(1) Choose any vertex, say vertex uk . Record uk . (For faster convergence, choose a
row with the most number of ones.)
(2) Add all rows i to row k for which the ith entry in row k is 1. Record all vertices
ui corresponding to such rows.
(3) If new non-zero entries appear in row k, repeat Step 2 for the corresponding rows.
(4) Otherwise, the recorded vertices and the edges incident with them for a component
(the component containing vertex uk ).
(5) If unrecorded vertices remain, then, ignoring the recorded vertices and the rows
corresponding to them, go back to Step 1.
MA32410 - GRAPHS AND NETWORKS 7

5. Eulerian Circuits and Trails


Definition 5.1. Let G be a connected graph or digraph.
An Eulerian trail in G is an open trail which contains every edge of G (exactly once,
by definition of a trail).
An Eulerian circuit in G is a circuit (i.e., a closed trail) containing every edge of G.
G is said to be Eulerian if G has an Eulerian circuit.*
Lemma 5.2. Let G be a graph in which every vertex has even degree. If e is any edge of
G, there exists a circuit containing e.
Proof. (To be revealed). □
Corollary 5.3. Let G be a graph in which every vertex has even degree.
(1) Every edge of G belongs to some cycle.
(2) Every non-isolated vertex is on some cycle.
Proof. (To be revealed). □
Theorem 5.4 (Euler). A connected graph is Eulerian if and only if every vertex has even
degree.
Proof. (To be revealed). □
The next theorem characterises graphs with Eulerian trails.
Theorem 5.5. Let G be a connected graph. Then G has an Eulerian trail if and only if
G has exactly two vertices of odd degree. In which case, every Eulerian trail begins and
ends with these two vertices.
Proof. (To be revealed). □
Remark 5.6. We proved earlier that if a graph has exactly two vertices, x and y say, of
odd degree then they are connected. However, the above theorem says more, namely that
x and y are connected by an Eulerian trail.
Eulerian graphs can be characterised as graphs that are essentially a collection of dis-
joint cycles. Recall that a set X is partitioned into non-empty subsets X1 , . . . , Xn if
X = X1 ∪ X2 ∪ · · · Xn and Xi ∩ Xk = ∅ for i ̸= k.
Theorem 5.7. Let G be a connected graph with non-empty edge list E. Then G is
Eulerian if and only if E can be partitioned into the edges of (disjoint) cycles.
The above proof of Euler’s Theorem can be adapted for digraphs to obtain:
Theorem 5.8. A connected digraph G is Eulerian if and only the out-degree of each
vertex in G is equal to its in-degree.
Definition 5.9. An edge e in a graph G is called a bridge if removal of the edge forms
a graph with more components than G.
Fleury’s Algorithm
Fleury’s algorithm finds an Eulerian circuit or an Eulerian trail if one exists.
Let G be a connected graph and L a list of edges of G. Initially L is empty.
(1) Check the vertex degrees: if more than 2 vertices of odd degree are found - STOP;
otherwise go to step 2.
(2) Choose a vertex x, of odd degree if one exists; otherwise any vertex will do.
*Some authors call G Eulerian if G has an Eulerian trail in our sense.
8 DR. GWION EVANS

(3) If δ(x) > 1, choose an edge xy that is not a bridge. Delete the edge xy from G
and adjoin it to the list L.
(4) If δ(x) = 1 and xy is the edge incident with x, delete the edge xy and vertex x
from G and adjoin xy to L.
(5) If there are any edges left incident with y, return to Step 3 with y as the ‘new’ x.
Otherwise - STOP.
(6) If L = E, then L gives the list of edges in order of an Eulerian circuit or trail;
otherwise G does not have an Eulerian circuit or trail.

6. Hamiltonian Cycles and Paths


Definitions 6.1. Let G = (V, E) be a connected graph or digraph. Then
• A Hamiltonian path in G is an open path which contains every vertex of G.
• A Hamiltonian cycle in G is a cycle containing every vertex.
• A Hamiltonian graph is a graph that contains a Hamiltonian cycle.
It is easy to construct Hamiltonian graphs, but extremely difficult to determine whether
a given graph is Hamiltonian or not – there is no efficient algorithm.
Examples 6.2.
(1) A graph consisting of a single cycle is Hamiltonian.
(2) Given any Hamiltonian graph, a graph obtained by adjoining any number of new
edges will also be Hamiltonian. For example, the complete graph, Kn , on n ≥ 3
vertices is Hamiltonian.
(3) A graph with a degree 1 vertex is not Hamiltonian.
The following theorem gives a necessary condition for a graph to be Hamiltonian. It
therefore helps to determine when a graph is not Hamiltonian.
Theorem 6.3. Let G be a Hamiltonian graph with n vertices and let k be a positive
integer such that k < n. Deleting any k vertices (and the edges on them) will leave a
graph with at most k components.
Proof. (To be revealed). □

6.1. A test for a graph NOT to be Hamiltonian. The converse to the above
theorem gives the following test for a graph not to be Hamiltonian:
Let G a graph. Suppose that for some integer k and for some choice of k vertices,
deleting these k vertices leaves a subgraph of G with more than k components, then G
is not Hamiltonian.

WARNING! If a connected graph satisfies the condition


(⋆) “deleting any k vertices leaves at most k components”
it does not mean that the graph is Hamiltonian. The simplest counterexamples are N1 and
K2 . Both of these graphs satisfy (⋆) but they are not Hamiltonian. A more complicated
and beautiful counterexample is the Petersen graph:„

„See, for example, the Wikipedia article at https://en.wikipedia.org/wiki/Petersen_graph#


Hamiltonian_paths_and_cycles
MA32410 - GRAPHS AND NETWORKS 9

6.2. Tests for a graph to be Hamiltonian. The following results give sufficient
conditions for a simple graph to be Hamiltonian
Theorem 6.2.1. Let G be a simple graph with n ≥ 3 vertices. If G has the property that
δ(u) + δ(v) ≥ n
for every pair of non-adjacent vertices u, v, then G is Hamiltonian.
Corollary 6.2.2. If G is a simple graph with n ≥ 3 vertices and in which every vertex
has degree at least 21 n, then G is Hamiltonian.

Corollary 6.2.3. Let G be a simple graph with n ≥ 3 vertices. If G has at least 21 (n −


1)(n − 2) + 2 edges then G is Hamiltonian.

7. Trees
Definition 7.1. Let G = (V, E) be a graph. Then
• G is said to be acyclic if G has no cycles;
• G is a tree if G is connected and acyclic;
• an acyclic graph is also called a forest;
• the trivial tree is N1 (i.e., a single vertex), it is the smallest tree; and
• a digraph is a tree if its underlying graph is a tree.
Theorem 7.2 (Alternative Characterisations of Trees).
(1) A graph with at least 2 vertices and no loops is a tree if and only if for every pair
of distinct vertices there exists a unique path connecting them.
(2) A connected graph is a tree if and only if every edge is a bridge.
(3) An acyclic graph is a tree if and only if it has the property that adjoining a new
edge creates a unique cycle in the extended graph, in which case the unique cycle
contains the new edge.
Proof. (To be revealed). □
Definition 7.3. A leaf in a tree is a vertex of degree 1.
Lemma 7.4. Every non-trivial tree has at least 2 leaves.
Proof. (To be revealed). □
Lemma 7.5. A tree with exactly n vertices has exactly n − 1 edges.
Proof. (To be revealed). □
10 DR. GWION EVANS

8. Labelled trees
Let G = (V, E) be a graph or digraph with |V | = n. Let S be a set with |S| = n. Given
a bijection θ : V → S, we say that G is labelled with labelling set S. The triple (G, θ, S)
forms a labelled graph.
A vertex u is said to be labelled θ(u).
The default labelling set will be taken to be {1, 2, . . . , n}.
Let (G, θ, S) and (H, ψ, S) be labelled graphs with the same labelling set S. A graph
isomorphism ϕ : G → H is called a labelled graph isomorphism if in addition ϕ satisfies
ψ ◦ ϕ = θ, i.e.,
ψ(ϕ(u)) = θ(u) for all u ∈ V (G).
The Prüfer Code of a Labelled Tree. Let T be a labelled tree with n vertices
labelled 1, 2, . . . , n (n > 1). Then its Prüfer code is a sequence of n − 2 integers (not
necessarily distinct) between 1 and n obtained as follows:
If n = 2 then the Prüfer code is the empty sequence. Otherwise
(1) Choose the unique leaf, x say, with least label. If the vertex adjacent to x is
labelled y, the code starts with y. Delete the vertex x and the edge xy.
(2) If there is more than one edge left, repeat Step 1 on the residual labelled tree to
find the next term of the code; otherwise stop.
The algorithm stops when only one edge remains; or equivalently, the code has exactly
n − 2 numbers.

The Labelled Tree of a Prüfer Code. Given a Prüfer code of length n − 2, to


determine the corresponding labelled tree T , with labels 1, 2, . . . , n.
(1) Initially the list is 1, 2, . . . , n. Let i be the least number in the list that is not in
the code. Then the edge iu is in T , where u is the first number in the code.
(2) Delete i from the list and the first term u of the code.
(3) If there are at least 3 numbers left in the list, go to Step 1.
(4) If there are just 2 numbers in the list, they form an edge of T . All edges in T have
now been found.
Note that if n = 2 then the algorithm produces K2 with one vertex labelled 1 and the
other labelled 2.

Theorem 8.1 (Cayley). The number of labelled trees on n ≥ 2 vertices is nn−2 .


Proof. (To be revealed). □

9. Spanning Trees and Minimum Weight Spanning Trees


Definition 9.1. A spanning subraph H of G is a subgraph with all the vertices of G. If
in addition H is a tree, the H is called a spanning tree (ST) of G.
Theorem 9.2. A graph has a spanning tree if and only if the graph is connected.
Proof. (To be revealed). □
Corollary 9.3. Let G be a connected graph with exactly n vertices. Then it has at least
n − 1 edges. Moreover, G has exactly n − 1 edges if and only if G is a tree.
Theorem 9.4. Let T be any tree with k edges. Let G be an simple graph in which ever
vertex has degree at least k. Then G has a subgraph isomorphic to T .
In this theorem we take the default labelling set and identify isomorphic labelled trees.
MA32410 - GRAPHS AND NETWORKS 11

Proof. (To be revealed). □


Corollary 9.5. Any simple graph in which all vertices have degree at least k contains an
open path of length k.
Weighting a graph or digraph means assigning a number to each edge, called the weight
or length of that edge. The weight/length of an edge e is denoted by W (e). We will
assume that W (e) is a non-negative integer (unless stated otherwise).
A weighted graph (digraph) is a graph (digraph) with a weighting. By default a graph
(digraph) can be thought of as a weighted graph (digraph) if we set W (e) = 1 for each
edge e.
The length or weight of a walk w in a weighted graph (digraph) is the sum of the
lengths/weights of the edges of the walk; it is denoted by W (w).
The weight of a subgraph H of a graph (digraph) G is the sum of the weights of all
edges in H; it is denoted by W (H).
Definition 9.6. Let G = (V, E) be a connected weighted graph. A minimum weight
spanning tree (MinWST) of G is a spanning tree of G of minimum weight.
(We can define a maximum weight spanning tree similarly.)

Prim’s Algorithm. Let G be a connected, simple, weighted graph with exactly n


vertices.
(1) Choose any vertex. Let T be the tree consisting of that single vertex.
(2) If all vertices of G are in T – STOP.
Otherwise, amongst all edges with one vertex in T and the other not in T choose
a shortest one and adjoin to T this edge and the end vertex which was not already
in T .
(3) Repeat Step 2 until the algorithm stops.
The final T is a MinWST of G.

Notation 9.7. Let G be a graph.


(1) Let e be an edge. If e is in G we write e ∈ G, otherwise we write e ∈
/ G.
(2) We denote by G + e the graph resulting from adjoining a new edge e to G (by
attaching it to existing vertices in G).
(3) For any edge f ∈ G, we denote by G − f the graph resulting from removing the
edge f from G.
(4) We denote the fact that H is a subgraph of G by H ⊆ G. If H is a graph which
is not a subgraph of G then we write H ̸⊆ G.
Theorem 9.8 (The Exchange Theorem for STs). Let T be a spanning tree of a simple
graph G and let e be any edge of G. Then T − f + e is a spanning tree of G for any f ∈ T
on the unique cycle in T + e.
Proof. (To be revealed). □
Proof that Prim’s Algorithm works. □

Tabular form of Prim’s Algorithm. Let G be a weighted connected simple graph


with n vertices. Let M be the n × n weight matrix of G, i.e.,
(
W (uv) if u and v are adjacent,
M (u, v) =
– otherwise.
We will grow a MinWST of G, T say, as follows. Note that at all times T is a tree.
12 DR. GWION EVANS

(1) Choose any vertex u. Initially T consists of u only. Delete the row of M corre-
sponding to u.
(2) If there are no undeleted rows left in M then STOP. Otherwise scan all columns
of M corresponding to vertices that are already in T . Choose a least entry, say
the (x, y)-th entry of M (if there is a choice, it does not matter which is chosen).
Adjoin the edge xy and the vertex x to T (the vertex y is already in T ). Delete
the x-th row of M .
(3) Repeat Step 2 until the algorithm stops.

Kruskal’s Algorithm. Let G be weighted connected graph with n vertices. This


algorithm grows a spanning forest F into a MinWST of G; at all times F is a spanning
forest G.
(1) List the edges of G in non-decreasing length order.
(2) Initially F consists of all vertices in G and the first edge in the list.
(3) Consider each edge of the list in turn. Adjoin an edge to F if and only if no cycle
is created.
(4) When F has n − 1 edges the algorithm stops. The current F is a MinWST.
NB: For MaxWST: replace non-decreasing by non-increasing; or scan the non-decreasing
list in reverse

Proof that Kruskal’s Algorithm constructs a MinWST in a simple connected weighted graph.

10. Shortest Path Algorithms


We will consider two algorithms that find shortest paths and their lengths in a weighted
digraph, namely:
• Dijkstra’s Algorithm: finds a shortest path to each reachable vertex from a fixed
origin, and their lengths; and
• the Warshall-Floyd Algorithm: given the weight matrix of a weighted digraph,
records the length of a shortest path from any vertex to any other vertex in a
matrix. The paths can be constructed using a so-called optimum policy matrix.
10.1. Dijkstra’s Algorithm. Let G be a weighted connected digraph. Choose any
vertex u of G and call it the origin.
A vertex is reachable from u if either x = u or there is a path from u to x.
The algorithm finds the shortest distance (length) from u to each reachable vertex x
and also a shortest path from u to x.
If there is no path from u to x then the algorithm gives the shortest distance as ∞.
If G is not connected, just apply the algorithm to each component of the underlying
graph of G.
The algorithm grows a directed tree T . (T is a spanning tree if and only if every vertex
is reachable from u).
T is called the shortest path tree.
T has the property that for any vertex x other than u in T there is a unique path from
u to x and this path is a shortest path from u to x in G.
The algorithm lables each vertex x with a pair (P (x), D(x)), where:
• D(x) is the current estimated shortest distance from u to x;
MA32410 - GRAPHS AND NETWORKS 13

• P (x) is a ’predecessor’ vertex on a putative shortest path.


At each stage, one vertex is declared permanently labelled and for such vertices the
estimated shortest distance is the actual shortest distance in G.
The non-permanently labels are then re-examined and their labels ‘updated’ if neces-
sary.

The Algorithm
(1) Label the origin u with (−, 0) and declare it permanently labelled. All other
vertices are labelled (u, ∞).
(2) If all vertices are permanently labelled the STOP.
Otherwise, suppose j ∗ is the latest vertex to be permanently labelled and con-
sider all vertices y for which j ∗ y is an edge in G. If W (j ∗ y) + D(j ∗ ) < D(y) then
change the label of y so that now:
P (y) = j ∗ and D(y) = W (j ∗ , y) + D(j ∗ ).
Otherwise, the label of y is unchanged.
(3) Examine all non-permanently labelled vertices. From all such vertices choose one,
say v, with the least estimated shortest distance D(v). Declare v to be permanently
labelled.
(4) Go back to Step 2.
Proof that Dijkstra’s Algorithm Works. □

10.2. The Warshall-Floyd Algorithm. The Warshall-Floyd algorithm is an adapta-


tion of Dijkstra’s algorithm.
Let G be a simple, connected weighted digraph (with no negative weights). This algo-
rithm finds the shortest distance from any vertex u to any other vertex v (∞ if no path
from u to v).
Let the vertices of G be 1, 2, . . . , n. Let W be the weight matrix of G.
Define n further n × n matrices W (i) , i = 1, . . . , n, recursively as follows.
First, define W (0) = W .
Suppose that W (k) has been constructed, where k < n. Then
n o
(k+1) (k) (k) (k)
Wi,j := min Wi,j , Wi,k+1 + Wk+1,j .

(k)
Then Wij is the distance of a shortest path from vertex i to vertex j (or ∞ if there is
no path from i to j) where all the vertices of the path, excluding i and j, are restricted
to {1, . . . , k}.
(n)
Thus, in the last matrix Wi,j is the shortest distance from vertex i to vertex j, or ∞
if there is no path from i to j.

The Optimum Policy Matrix. The Optimum Policy Matrix (OPM) correspond-
ing to the digraph G is an n × n matrix Z, which can be:
(a) computed alongside the matrices W (i) ; or
(b) computed at the end of the Warshall-Floyd algorithm.
14 DR. GWION EVANS

In case (a), Z has – in every position in which the weight matrix W has ∞. Elsewhere,
Zij = j. Z is updated at each stage as follows.

If when W (t) is being computed the (i, j) entry changes (so it is different from that of
W (t−1) , then change the (i, j) entry of Z to t.
Do this for t = 1, 2, . . . , n. The final Z is the OPM.

In case (b), the final OPM Z can be constructed after the Warshall-Floyd algorithm
has stopped.
This is done by comparing the first matrix W (0) with the last one W (n) .
(1) Put – in every position in Z where the last matrix W (n) has entry 0 or ∞.
(2) If the (i, j) entries of W (0) and W (n) are equal (but not 0 or ∞), then put Zij = j.
(3) Otherwise,if they are different and the (i, j) entry of W (n) first appears in W (t) ,
then put Zij = t.

Constructing shortest paths from the OPM. To find the shortest path, as given
by the OPM, from vertex i to vertex j (if paths exist), the following algorithm is used.
(1) If Zij = –, there is no path from i to j. Otherwise, initially S = ij.
(2) Suppose
u1 u2 . . . um
is the current S, where u1 = i and um = j. Then for each 1 ≤ k < m, if
Zuk ,uk+1 = x, where x ̸= –, uk , uk+1 , place vertex x between uk and uk+1 , i.e., the
new S is u1 . . . uk xuk+1 um .
(3) If no new vertices are adjoined to the current S then STOP. Otherwise, go back
to Step 2.
When the algorithm stops, S is the shortest path from i to j given by the OPM.

11. Longest Path Algorithm


Let G be a weighted digraph with n vertices (where the weights are non-negative). The
Longest Path Algorithm (LPA) finds all longest paths in G from a given vertex, called
the origin, to each other vertex. If no path exists from the origin to a vertex, the longest
distance is given as 0. If a path does exist, the LPA also gives a way of determining a
longest path.
First the digraph must be prepared by ordering (or sorting) the vertices into so-called
topological order.
Definition 11.1. (Topological Ordering) Let G be a digraph with exactly n vertices. Let
S be an ordered set of size n; usually S is {1, 2, . . . , n} or {0, 1, . . . , n − 1}. If the vertices
of G are labelled by S via ℓ : V (G) → S, then G is said to be topologically ordered if
whenever xy is an edge of G then ℓ(x) < ℓ(y) (sometimes we omit ℓ and just write x < y).
A vertex u is said to be of lower (higher) rank than a vertex v if ℓ(u) < ℓ(v) (ℓ(u) > ℓ(v)).
The Topological Ordering Algorithm
Let G be a digraph.
(1) If there are no vertices of zero in-degree the digraph is not acyclic and therefore
cannot be topologically ordered – STOP.
Otherwise choose a vertex of zero in-degree and label it 0. Delete this vertex
and all edges on it.
MA32410 - GRAPHS AND NETWORKS 15

(2) Suppose there are vertices remaining. If there are no vertices of zero in-degree in
the residual graph, STOP.
Otherwise choose a vertex of zero in-degree and label it m + 1 if the previous
label given to a vertex was m. Delete the vertex m + 1 and all edges on it (they
will all be edges out of the vertex labelled m + 1).
(3) Repeat Step 2 until the algorithm stops.
If when the algorithm stops there are unlabelled vertices, then the digraph G is not acyclic
and therefore cannot be topologically ordered. Otherwise, if all vertices are labelled, then
G has been topologically ordered (and is therefore acyclic).
The Longest Path Algorithm
Let G be a weighted digraph with n vertices (where the weights are non-negative). Let
u be the origin.
In this algorithm each vertex x is assigned a label (P (x), D(x)), where
• P (x) is a predecessor vertex on a longest path from u to the vertex x,
• D(x) is the longest length from u to the vertex x.
The Algorithm
(1) Apply the topological ordering algorithm to G. If the algorithm fails, then G has
cycles and the LPA will not work, in which case STOP.
(2) Otherwise, suppose the vertices of G are topologically ordered. Wlog § we may
assume the vertices of G are in topological order 0, 1, 2, . . . , n−1, where we identify
the vertices of G with the labels 0, 1, . . . , n − 1, and u = 0.
(3) Assign the label (–, 0) to u.
(4) Suppose the vertices 0, 1, . . . , x − 1 have been already been labelled, where x ≥ 1.
If x = n, then STOP. Otherwise, consider all vertices y for which yx is an edge.
Then y is already labelled (since y < x). From all such vertices y, choose one for
which
D(y) + W (yx)
is a maximum. Then label the vertex x with (y, D(y) + W (yx)).
(5) If all vertices have been labelled – STOP. Otherwise go back to Step 4.
Theorem 11.2. Applying the Topological Ordering Algorithm to a digraph G results in
either a topological ordering of G if G is acyclic, or some vertices left unlabelled otherwise.
Proof. (To be revealed). □
Corollary 11.3. A digraph G is acyclic if and only if G can be topologically ordered.
Proof. (To be revealed). □

12. Activity Networks


Definition 12.1. Let G be a simple, weighted digraph, with all weights non-negative.
Then G is a activity network if
(1) G is acyclic;
(2) G has exactly one vertex s of in-degree zero and exactly one vertex t of out-degree
zero, where s ̸= t; and
(3) for any given vertex x(̸= s) of G, all edges out of x have the same non-zero length;
all edges out of s have zero length.
§We need only consider the subgraph consisting of the vertices of rank equal to or greater than that of the origin. Then
we can re-apply the topological ordering to this subgraph so that the origin is labelled by 0 and all labels 0, 1, . . . , n − 1 are
used, where now n is the number of vertices in the subgraph.
16 DR. GWION EVANS

Projects. Activity networks are used to model projects. A project consists of activi-
ties. Each activity is given a time, the time required to complete that activity.
A crucial part of planning the project is to identify the immediate predecessors
(IPs) of each activity A; i.e., the activities that must be completed before A can be
started. (The term immediate refers to the assumption that it is immediately obvious
that X must be completed before A can start.)
There are two notional activities called start and finish, denoted by s and t, respec-
tively; each has time 0.
It is stipulated that:
• the start activity s has no IPs;
• the finish activity t is not an IP of any activity;
• if an activity X has no IPs, then it is assigned notionally s as an IP;
• if an activity X is not the IP of any activity, then it is defined notionally to be an
IP of t.
The project is said to be feasible if all its activities can be completed.
Associated Digraph. Associated with a given project is its weighted associated di-
graph G. The vertices of G are the activities of the project and its edges are ordered
pairs of activities XY , where X is an IP of Y . The length of the edge XY is defined
to be the time of the activity X. (Thus all edges out of X have the same length: the
time of X.) An activity X is said to be a predecessor of an activity Y , and that Y is a
successor of X, if there is a non-trivial path in G from X to Y .
Lemma 12.2. Let G be the digraph associated to a feasible project. Then:
(1) G is an activity network;
(2) every activity is on a path from s to t in G;
(3) every activity, other than s, is a successor of s; and
(4) every activity, other than t, is a predecessor of t.
Proof. (To be revealed). □
The length of any edge from an activity is the time needed to complete that activity.
The following statement is an easy consequence of this fact:
the time needed to complete all but the last activity on a path is the sum of the
edge lengths of the path, i.e., the length of the path.
Thus an activity A cannot start until all its predecessors are finished; or equivalently
(by Lemma 12.2), until every activity on every path from s to A is finished.
It follows that the earliest start time (EST) of A, denoted by EST(A), is the
length of a longest path from s to A.
Any longest path from s to t is called a critical path and all activities on a critical
path are called critical activities.
The earliest completion time (ECT) of the project is the shortest time in which
all its activities can be completed. It is clear that
ECT = EST(t) = Length of a critical path.
(In that time all predecessors of t, i.e., (by Lemma 12.2) all activities, will be finished.)
Theorem 12.3. A project is feasible if and only if its associated digraph is an activity
network.
Proof. (To be revealed). □
MA32410 - GRAPHS AND NETWORKS 17

The latest start time (LST) of an activity A, denoted by LST(A), is the latest time
that A can be scheduled to start and the project still completed in its ECT.
All successors of A, as well as activity A, need to be completed and (by Lemma 12.2)they
all lie on paths from A to t. Therefore, the minimum time needed to complete all successors
of A is the length of a longest path from A to t. During that time all successors of A can
be completed. It follows that
LST(A) = ECT - (the longest path length from A to t).

The slack of an activity A is defined to be LST(A) − EST(A). It is a measure of the


flexibility of scheduling A at the outset. Once the project is underway, the current slack
time of A may change depending on when the predecessors of A start.

Finding a critical path and the ECT, ESTs and LSTs. Applying the Longest Path
Algorithm (LPA) to the activity network G of a feasible project will give all ESTs, a
critical path and the ECT. This is known as the forward scan. (The origin is necessarily
s; the only vertex of in-degree zero.)
Since the length of a longest path from an activity A to t is equal to the length of
a longest path from t to A in the reverse activity network, we compute this length for
all activities by applying the LPA to the reverse digraph of G (necessarily with t as the
origin). This is known as the reverse scan.

13. Transport Networks


Let G be a digraph. Then G is a transport network (TN) if the following hold:
(1) G is weighted and connected.
(2) All weights in G are non-negative.
(3) Certain vertices are designated sources or sinks and there is at least one of each.
A source must have non-zero out-degree and a sink must have non-zero in-degree.
The length of an edge in TN theory is called its capacity.
A standard (or basic) TN has a unique source and this source has in-degree zero (a
super source), and a unique sink and this sink has out-degree zero (a super sink).
Any TN can be converted into a standard TN. Introduce two new vertices x and y.
New edges are defined as follows.
For each current source u define xu to be a new edge, of default length ∞ (in some
cases, a finite capacity can be assigned, depending on the situation). Similarly, for each
current sink v, define vy to be an edge, default length ∞. In the extended TN, the only
source is declared to be x and the only sink y.
Assumption 13.1. Unless otherwise stated, TN should be taken to mean a standard TN.
The unique (super) source and sink are denoted by x and y respectively.
Flows. Let G be a TN. Denote the capacity of an edge e by c(e).
A flow in a TN is an assignment of a number f (e) to each edge, called the flow along
the edge e, satisfying:
(1) 0 ≤ f (e) ≤ c(e) for every edge e.
(2) (Conservation of Flow) If u is a vertex, which is not the source or sink, the total
flow (along all edges) into u equals the total flow (along all edges) into out of u.
(That is, what flows in flows out of u.)
There is always at least one flow in a TN, namely the zero flow in which the flow
along each edge is zero.
For each flow f , the total flow out of the source of a TN is the value of the flow f .
18 DR. GWION EVANS

Theorem 13.2. The value of a flow equals the total flow into the sink.
Cuts. Recall that a TN is connected, which means its underlying graph (UG) is con-
nected. A set C of edges of a TN G is called a cut if deletion of these edges from G would
disconnect the UG of G into two components X and Y , such that x ∈ X and y ∈ Y .
(That is, deleting C disconnects, in the UG of G, the source form the sink.)
Edges of C from X to Y (i.e., with initial vertex in X and final vertex in Y ) are called
forward edges, while edges of C from Y to X are reverse edges.
A TN always has a cut, e.g. the cut consisting of all edges out of the source.
The capacity of the cut C is the sum of the capacities of its forward edges (thus the
reverse edge capacities contribute nothing to the capacity of C).
Theorem 13.3. The value of any flow is less than or equal to the capacity of any cut.
A max-flow is a flow of maximum value in a TN. A min-cut is a cut of minimum
capacity in a TN.
Corollary 13.4. A flow is a max-flow in a TN if across any cut, all forward edges are
saturated and all reverse edges have zero flow.
Conversely, a cut is a min-cut if for any flow, all forward edges of the cut are saturated
and all reverse edges have zero flow.
Theorem 13.5 (The Max-Flow-Min-Cut Theorem). The maximum flow value in any
TN equals the minimum cut capacity.
The celebrated ‘Max-Flow-Min-Cut Theorem’ was proved in 1956 by Ford and Fulker-
son. Crucial to proving this theorem is the following Lemma:
Lemma 13.6. If in a TN, the value of some flow f is equal to the capacity of some cut
C, then f is a max-flow and C is min-cut.
The Max-Flow-Min-Cut Theorem uses an algorithm (the Ford-Fulkerson Algorithm)
that constructs a flow and a cut such that the value of the flow is the capacity of the cut.
The flow is therefore a max-flow. The resulting max-flow ‘saturates’ each forward edge
of the cut (i.e., the flow along the edge equals the edge’s capacity) and there is zero flow
along each reverse edge.

The Ford-Fulkerson Algorithm. Let G be a standard transport network with source


x and sink y. The algorithm starts with any flow f (which could be the zero flow) and
determines whether the value of f can be increased; if it cannot then f is a max flow.
The algorithm sets out on a path, in the underlying (undirected) graph (UG) of G,
trying to reach the sink y, labelling vertices along the way. At each vertex v of the path
the algorithm records the predecessor vertex u, whether uv or vu is an edge in the digraph
G and, most important of all, carries a running positive float of how much the flow could
be increased along the path without violating the Conservation of Flow. If all attempts
to reach y fail, the flow is then a max-flow. If the path reaches y then the flow f can be
adapted to produce a flow f ∗ whose value is that of f plus the final float ∆(y) at y. The
algorithm is then repeated with f ∗ in place of f . Continuing in this way, the flow value
is increased until a max-flow is achieved.
Algorithm 13.7.
(1) Start with any flow f in G.
(2) Label x with (–, ∞).
(3) Try to form a path from x to y in the UG of G as follows.
MA32410 - GRAPHS AND NETWORKS 19

If v is an unlabelled vertex, choose any labelled vertex u for which either:


(a) uv is an unsaturated edge in G (i.e., c(uv) − f (uv) ̸= 0); or
(b) vu is an edge in G with f (vu) ̸= 0.
In case (a), label v by (u+ , ∆(v)), where ∆(v) := min{∆(u), c(uv) − f (uv)}.
In case (b), label v by (u− , ∆(v)), where ∆(v) := min{∆(u), f (vu)}.
Once y is labelled go to Step 4. If after labelling every vertex that can be
labelled, y is not labelled – STOP.
(4) Adjust the flow f to a new flow f ∗ as follows.
Backtrack through predecessor vertices from y to x and, on the way, do the
following at each vertex v:
(a) if v is labelled (u+ , ∆(v)), then f ∗ (uv) = f (uv) + ∆(y);
(b) if v is labelled (u− , ∆(v)), then f ∗ (vu) = f (vu) − ∆(y).
(This path in the UG obtained by backtracking is called an augmenting path.)
Furthermore, f ∗ (e) = f (e) for each edge e not on the augmenting path.
(5) Delete the labels on all vertices apart from x, then repeat from Step 3 using f ∗
instead of f .
Outcomes of the Algorithm.
When the algorithm stops:
(1) the current flow is a max-flow;
(2) the vertex set of G is partitioned into two non-empty subsets, X and Y :
• X consists of all labelled vertices and therefore contains x,
• Y consists of all unlabelled vertices and therefore contains y;
(3) the edges with one vertex in X and the other in Y form the min-cut;
(4) the flow along any reverse edge of the min-cut (from Y to X) is zero;
(5) all forward edges of the min-cut (from X to Y ) are saturated.
Remarks 13.8.
• It is necessary to label every vertex that can be labelled in order to be able to
claim that the sink y cannot be labelled and that therefore the current flow is a
max-flow.
• Notice that in Step 4, flows along edges of the backtrack path are increased or
decreased by the same amount, namely ∆(y).

You might also like