Applied Graph Theory
Applied Graph Theory
Contents
List of Symbols 2
1 Introduction 3
2 Cartesian Products 4
5 Distances 6
6 Connectedness 6
7 Graph Isomorphism 7
8 Self-Complementary Graphs 8
9 Bipartite Graphs 9
10 Trees 9
11 Blocks 11
12 Line Graphs 12
13 Adjacency Matrices 13
14 Incidence Matrices 15
15 Dijkstra’s Algorithm 16
16 Prim’s Algorithm 18
1
VM
List of Symbols
+(⌧) Vertex set of graph ⌧
⇠ is adjacenct to
2
VM
1 Introduction
A graph is an ordered pair ⌧ = (+ , ⇢) where + is a non-empty set called the vertex set,
whose elements are the vertices of ⌧, and ⇢ is a set of unordered pairs of distinct vertices of
⌧, whose elements are the edges of ⌧. The order of ⌧ is its number of vertices and the size
of ⌧ is its number of edges.
Two vertices D and E of ⌧ are adjacent, denoted by D ⇠ E, if DE 2 ⇢ (note that DE here
denotes an unordered pair of vertices, and DE = ED). If there is no edge between D and E,
then they are nonadjacent, denoted by D / E. The vertex E and the edge DE are said to be
incident with each other. The degree of a vertex E is the number of edges incident with it, or
equivalently, the number of vertices adjacent with it, and is denoted by deg(E).
Lemma 1.1 (Handshaking Lemma). The sum of the degrees of all vertices of a graph is twice
its size.
Õ
Proof. Let ⌧ be a graph, and consider the sum of its degrees, E2+(⌧) deg E. As each edge is
incident with exactly two vertices, each edge is counted once by two terms in this summation.
Thus, the sum is equal to twice the number of edges. É
Corollary 1.2. The number of vertices of odd degree in a graph is always even.
Considering the vertices of odd and even degrees, we can write (1) as
’ ’
deg E + deg E = 2|⇢(⌧)|. (2)
E2+(⌧) : deg E odd E2+(⌧) : deg E even
Both the RHS and the second term on the LHS are even integers, and therefore so is the first
term on the LHS. But a sum of odd integers is even only if the number of terms is even. Thus,
⌧ has an even number of vertices of odd degree. É
A regular graph is a graph in which all vertices have the same degree. This common value
of the degree is the regularity of the graph. A regular graph of regularity : is a :-regular
graph. A cubic graph is a 3-regular graph.
Exercise 1.1. Prove that any cubic graph has even order. For which other regular graphs will
this statement hold?
Theorem 1.3. In any graph on two or more vertices, at least two vertices have the same degree.
3
VM
2 Cartesian Products
The Cartesian product of two graphs ⌧ and is the graph denoted by ⌧ ⇥ , whose vertex
set is +(⌧) ⇥ +( ) (the Cartesian product of the vertex sets +(⌧) and +( ), consisting of all
ordered pairs (D, E) where D is a vertex of ⌧ and E is a vertex of ), in which two vertices
(D1 , E1 ) and (D2 , E2 ) are adjacent if and only if either D1 = D2 and E1 ⇠ E2 or D1 ⇠ D2 and
E1 = E2 .
Exercise 2.1. Prove that if ⌧ is a graph of order ?1 and size @ 1 , and is a graph of order ?2
and size @ 2 , then ⌧ ⇥ is a graph of order ?1 ?2 and size ?1 @ 2 + ?2 @ 1 .
Solution. By definition, the vertex set of ⌧ ⇥ is the Cartesian product +(⌧) ⇥ +( ) of the
vertex sets of ⌧ and , and therefore contains |+(⌧)| ⇥ |+( )| elements. Thus, the order of
⌧ ⇥ is ? 1 ?2 .
Now, consider any vertex (D, E) of ⌧ ⇥ . Corresponding to every vertex D 0 adjacent to D
in ⌧, there is an edge from (D, E) to (D 0 , E)) in ⌧ ⇥ . Similarly, corresponding to every vertex
E 0 adjacent to E in , there is an edge from (D, E) from (D, E 0) in ⌧ ⇥ . Thus, the degree of
(D, E) in ⌧ ⇥ is deg D + deg E. Hence, by the Handshaking Lemma, the size of ⌧ ⇥ is half
the sum of its vertex degrees, which is
1 ’ 1 ’ 1 ’
(deg D + deg E) = deg D + deg E
2 2 2
D2+(⌧),E2+( ) D2+(⌧),E2+( ) D2+(⌧),E2+( )
©1 ’ ™ ©1 ’ ™
= ?2 ≠ deg D Æ̈ + ?1 ≠ deg E Æ̈
2 2
´ D2+(⌧) ´ E2+( )
= ?2 @1 + ?1 @2 .
Exercise 2.2. Show that if ⌧ is an A-regular graph and is an B-regular graph, then ⌧ ⇥
is a regular graph of regularity A + B.
4
VM
v1 v2 v3 v4 v1 v2 v4 v1 v2 v3 v4 v1 v2 v4
v7 v6 v5 v7 v5 v7 v6 v5 v7 v5
(a) ⌧ (b) 1 (c) 2 (d) 3
Exercise 3.2. Show that if ⌧ and ⌧ are regular graphs of order = with the same regularity,
then the regularity is even and = = 4C + 1 for some integer C.
b c
a d
f e
b c
a d
f e
This walk is not a path, since the vertex 4 is repeated. An example of a path from 1 to 2 in
the same graph ⌧ is 1, 5 , 4 , 2. The length of this path is 3.
5
VM
b c
a d
f e
A cycle of length 4 in ⌧ is 1, 5 , 4 , 2, 1.
b c
a d
f e
5 Distances
The distance between two vertices D and E of a graph ⌧ is the length of a shortest path
between D and E – such a shortest path between D and E is a geodesic from D to E. Thus, the
distance between D and E in ⌧, denoted by 3⌧ (D, E) is the length of a geodesic from D to E in
⌧. When the graph ⌧ is clear from the context, we will write 3⌧ (D, E) as 3(D, E).
The eccentricity of a vertex E, denoted by ecc(E), is the maximum of all distances from E
to any other vertex. That is,
ecc(E) = max 3(D, E).
D2+(⌧)
The diameter of ⌧ is the maximum of the eccentricities of vertices of ⌧, and the radius
of ⌧ is the minimum of the eccentricities of vertices of ⌧. They are denoted by diam(⌧) and
rad(⌧) respectively. Thus,
The set of all vertices of ⌧ having minimum eccentricity,i.e. the set of all E 2 +(⌧) such
that ecc E = rad ⌧, is the centre of ⌧.
6 Connectedness
A graph is connected if there is a path between every two of its vertices. Otherwise, it is
disconnected. A (connected) component of a graph ⌧ is a maximal connected subgraph of
⌧. Thus, a graph ⌧ is connected if and only if it has exactly one component.
Proof. Consider a graph ⌧, and suppose that ⌧ is disconnected. We shall show that ⌧ is
connected, by showing that there is a path between every two vertices of ⌧.
6
VM
Let D and E be any two vertices of ⌧. If they are not adjacent in ⌧, then they are adjacent
in ⌧, and hence there is a path DE from D to E in ⌧. If D and E are adjacent in ⌧, then
they belong to the same component of ⌧. As ⌧ is disconnected, it has at least one more
component containing at least one vertex, say F, which is necessarily non-adjacent to both D
and E. Hence, in ⌧, F is adjacent to both D and E. Thus, there is a path DFE from D to E in
⌧. Therefore, ⌧ is connected. É
Theorem 6.2. For any connected graph ⌧, if diam ⌧ 3, then diam ⌧ 3.
Proof. Consider a graph ⌧ of diameter at least 3. Then there exist vertices D and E in ⌧ such
that 3⌧ (D, E) = 3. This implies that D and E are non-adjacent in ⌧, and hence adjacent in ⌧.
Now, consider any two vertices G and H other than D and E. In ⌧, G can be adjacent to
at most one of D and E, for otherwise, 3⌧ (D, E) = 2. Hence, G is adjacent to at least one of
D and E in ⌧. Similarly, H is adjacent to at least one of D and E in ⌧. Thus, there is a path
of length at most 3 from G to H in ⌧ (namely GD H, GEH, GDEH, or GED H), which implies that
3⌧ (G, H) 3. Therefore, diam ⌧ 3. É
7 Graph Isomorphism
An isomorphism from a graph ⌧ to a graph is a bijective1 function 5 : +(⌧) ! +( ) such
for all vertices D and E of ⌧, D ⇠⌧ E if and only if 5 (D) ⇠ 5 (E). In other words, a graph
isomorphism is a bijection from the vertex set of the first graph to that of the second, that
preserves both edges and non-edges. If there exists an isomorphism from ⌧ to , then ⌧ and
are isomorphic. Then we write ⌧ .
Isomorphic graphs have exactly the same structure –i.e. all properties of the graph that do
not depend on the labelling or drawing will be shared by isomorphic graphs. For example,
isomorphic graphs have the same order, size, degree sequence, diameter, and radius. Indeed,
if 5 is an isomorphism from ⌧ to , and E is a vertex of ⌧, then the neighbours of 5 (E) in
are the images of the neighbours of E in ⌧, and deg⌧ E = deg 5 (E). Similarly, if D and E are
two vertices of ⌧, then 3⌧ (D, E) = 3 ( 5 (D), 5 (E)).
Theorem 7.1. Graph isomorphism is an equivalence relation on the class of all graphs.
Proof. To show that graph isomorphism is an equivalence relation, we need to show that
is a reflexive, symmetric, transitive relation between graphs. First, observe that the identity
map on the vertex set of a graph is an isomorphism from the graph to itself – for, if ⌧ is a
graph and id denotes the identity map on its vertex set then for any two vertices D and E of
⌧, D ⇠ E if and only if id(D) ⇠ id(E), as id(D) = D and id(E) = E. Hence, is reflexive.
Next, suppose that ⌧ . Then there exists an isomorphism 5 from ⌧ to . Since
5 : +(⌧) ! +( ) is bijective, it has an inverse 5 1 : +( ) ! +(⌧). We claim that 5 1
is an isomorphism from to ⌧. We know that 5 1 is bijective. To see that it preserves
edges and non-edges, observe that if G and H are two vertices of , then G = 5 ( 5 1 (G)) and
H = 5 ( 5 1 (H)), which implies that G ⇠ H if and only if 5 1 (G) ⇠⌧ 5 1 (H) (since 5 is an
isomorphism from ⌧ to ). Therefore, 5 1 is an isomorphism from to ⌧. This shows that
⌧. Thus, is symmetric.
Finally, suppose that ⌧ and . Then there exist isomorphisms 5 from ⌧ to
and 6 from to . We claim that 6 5 is an isomorphism from ⌧ to . Indeed, 6 5 is a
function from +(⌧) to +( ), and being a composition of bijections, is itself a bijection. Now,
1 injective and surjective;i.e. one-to-one and onto
7
VM
suppose D and E are two vertices of ⌧. Then D ⇠⌧ E if and only if 5 (D) ⇠ 5 (E) (since 5 is an
isomorphism from ⌧ to ) if and only if 6( 5 (D)) ⇠ 6( 5 (E)) (since 6 is an isomorphism from
to ). Thus, 6 5 is an isomorphism from ⌧ to . Therefore, is transitive. É
8 Self-Complementary Graphs
A graph is self-complementary if it is isomorphic to its complement –i.e. ⌧ is self-complementary
if ⌧ ⌧. For example, 1 , %4 and ⇠5 are self-complementary graphs of orders 1, 4, and 5
respectively. There is one more self-complementary graph of order 5, namely the bull graph,
which can be constructed by adding one new vertex to %4 and making it adjacent to the two
non-pendant vertices of the path. This graph is shown below.
Theorem 8.1. The order of any self-complementary graph is 4: or 4: + 1, for some non-negative
integer :.
Proof. Let ⌧ be a self-complementary graph of order = and size <. Then the size of ⌧ is
= =(= 1)
2 <. Since ⌧ ⌧, < = =2 <, which implies that < = 12 =2 = 4 . As < is an integer,
this implies that 4 divides =(= 1), which in turn implies that either one of = and = 1 is
divisible by 4, or both = and = 1 are even. Since the latter is not possible, it follows that
= = 4: or = 1 = 4:,i.e. = = 4: or 4: + 1 for some integer :. É
From Theorem 6.1, we know that a graph and its complement cannot both be discon-
nected. Thus, if ⌧ is a disconnected graph, then ⌧ must be connected, and therefore it cannot
be isomorphic to ⌧. This implies that a self-complementary graph is necessarily connected.
Corollary 8.2. Every self-complementary graph is connected. É
Similarly, from Theorem 6.2, we obtain the following corollary about the diameter of
self-complementary graphs.
Corollary 8.3. Every non-trivial self-complementary graph has diameter 2 or 3.
Proof. Consider a non-trivial, self-complementary graph ⌧, and suppose that it has diameter
strictly greater than 3. Then, by Theorem 6.2, diam ⌧ 3, which implies that diam ⌧ <
diam ⌧, a contradiction, since ⌧ ⌧. Hence, diam ⌧ 3. On the other hand, a non-trivial
graph cannot have diameter 0, hence diam ⌧ 1. But if diam ⌧ = 1, then ⌧ is a non-
trivial complete graph, whose complement is a totally disconnected graph, which is again
impossible. Hence, diam ⌧ = 2 or 3. É
Exercise 8.1. If ⌧ is a regular self-complementary graph of order =, show that = = 4: + 1,
for some integer :, and diam ⌧ = 2.
Exercise 8.2. Let ⌧ be a self-complementary graph, and let be the graph obtained by
taking the disjoint union of and %4 , and making every vertex of adjacent to the two
non-pendant vertices of this %4 . Then show that is also self-complementary. What is the
graph obtained in this manner if ⌧ = 1 ?
8
VM
Exercise 8.4. Show that for each positive integer = of the form 4: or 4: + 1, where : is an
integer, there exists at least one self-complementary graph of order =.
9 Bipartite Graphs
A graph ⌧ = (+ , ⇢) is bipartite if its vertex set + can be partitioned into two subsets +1 and +2
such that no two vertices in +8 are adjacent, for 8 = 1, 2. That is, there exist two non-empty,
disjoint subsets +1 , +2 ✓ + such that +1 [ +2 = +, and every edge of ⌧ (if any) joins a vertex
in +1 with a vertex in +2 . Then we say that (+1 , +2 ) is a bipartition of ⌧.
The following theorem characterises bipartite graphs in terms of its cycles. A cycle is even
if its length is even and odd if its length is odd.
Proof. First, suppose that ⌧ is a bipartite graph with bipartition (+1 , +2 ), and let E1 , E2 , . . . , E :
be a cycle of length : in ⌧. Without loss of generality, suppose that E1 2 +1 . Then, since
E2 ⇠ E1 , E2 2 +2 , which in turn implies that E 3 2 +1 , as E2 ⇠ E 3 . Proceeding similarly, we
see E 8 2 +1 if 8 is odd and E 8 2 +2 if 8 is even. But E : ⇠ E1 and E1 2 +1 implies that E : 2 +2 .
Therefore, : (the length of the cycle) is even.
Conversely, suppose ⌧ is a graph that has no odd cycles. Without loss of generality, assume
that ⌧ is connected – otherwise, apply the argument to each component. Let E be any vertex
of ⌧. Define subsets +1 and +2 of +(⌧) as follows:
+1 = { D 2 + | 3(D, E) is even }
+2 = { D 2 + | 3(D, E) is odd }.
; = 3(F, G) + 3(F, H) + 1
= [3(E, G) 3(E, F)] + [3(E, H) 3(E, F)] + 1
= 3(E, G) + 3(E, H) 23(E, F) + 1.
If G, H 2 +1 , then both 3(E, G) and 3(E, H) are even, and if G, H 2 +2 , then both these numbers
are odd. In either case, 3(E, G) + 3(E, H) is even, and hence ; is odd, which is a contradiction.
Hence, (+1 , +2 ) is a bipartition of ⌧ as claimed. É
10 Trees
A tree is a connected, acyclic graph. There are several well known characterisations or al-
ternative definitions of trees. We take the given definition as the basic one and prove its
equivalence to some others.
9
VM
Theorem 10.1. A graph ) is a tree if and only if there is a unique path joining every two vertices
of ).
Proof. First, suppose that ) is a tree, and let D and E be vertices of ). Since ) is connected,
there is a path, say %1 , joining D and E. Now we must show that this path is unique. Assume
to the contrary that there exists another path %2 from D to E. When traversing %1 from D to E,
let F be the first vertex that is present on %1 but not %2 . Let G be the vertex on %1 preceding
F, and note that G is on %2 as well. Let H be the next vertex common to both %1 and %2 when
traversing %1 from G to E. Then the portion of %1 from G to H together with the portion of %2
from H to G forms a cycle in the tree ), which is a contradiction. Thus, %1 is the unique path
joining D and E.
Conversely, suppose that ) is a graph in which there is a unique path joining any two
vertices. Clearly, ) is connected. To show that ) is acyclic, suppose that E 1 , E2 , . . . , E = is a
cycle in ). Then we get two different paths joining E1 and E = , namely the path E 1 , E2 , . . . , E =
and the path E 1 , E = (since E1 ⇠ E = in the cycle). This contradicts our assumption. Thus, )
must be acyclic and hence is a tree. É
The next two results show that the size of a tree is always one less than its order, and
that conversely, this property together with either connectedness or acyclicity implies that
the graph is a tree.
Theorem 10.2. A (?, @)-graph ) is a tree if and only if it is connected and ? = @ + 1.
Proof. Let ) be a tree with ? vertices and @ edges. Then ) is connected. We prove that
? = @ + 1 by induction. This is clearly true when ? = 1. Assume it to be true for all trees of
order less than ?. Now in ), we know that every two vertices are joined by a unique path.
Thus, if 4 is any edge of ), then the graph ) {4} obtained by deleting 4 has exactly two
components, say )1 and )2 . Each one is a tree, since it is connected and acyclic. Let )8 have
? 8 vertices and @ 8 edges, 8 = 1, 2. Then by the hypothesis, ? 8 = @ 8 + 1 (since ? 8 < ?). But
? = ?1 + ? 2 and @ = @ 1 + @ 2 + 1 (since the size of ) {4} is one less than that of )). Thus,
? = @ 1 + @ 2 + 2 = @ + 1.
For the converse, suppose that ) is a connected (?, @)-graph with ? = @ + 1. We must
show that is acyclic. Suppose to the contrary that ) has a cycle ⇠ with : vertices. Then ⇠
has : edges as well. Since ) is connected, there is a path from every vertex not on ⇠ to some
vertex of ⇠. The shortest path from each vertex E not on ⇠ to a vertex on ⇠ has a unique
edge incident with E, which is not part of ⇠. Since there are ? : vertices in ) not on ⇠,
there are ? : such edges. Thus @ (? :) + : = ?, which contradicts our assumption that
? = @ + 1. Thus, ) must be acyclic. É
In the following theorem, the proof of the direct part is identical to that of Theorem 10.2,
except for the assertion being about acyclicity rather than connectedness. The proof of the
converse part is entirely different.
Theorem 10.3. A (?, @)-graph ) is a tree if and only if it is acyclic and ? = @ + 1.
Proof. Let ) be a tree with ? vertices and @ edges. Then ) is acyclic. We prove that ? = @ + 1
by induction. This is clearly true when ? = 1. Assume it to be true for all trees of order less
than ?. Now in ), we know that every two vertices are joined by a unique path. Thus, if 4
is any edge of ), then the graph ) {4} obtained by deleting 4 has exactly two components,
say )1 and )2 . Each one is a tree, since it is connected and acyclic. Let )8 have ? 8 vertices and
@ 8 edges, 8 = 1, 2. Then by the hypothesis, ? 8 = @ 8 + 1 (since ? 8 < ?). But ? = ?1 + ?2 and
@ = @ 1 + @ 2 +1 (since the size of ) {4} is one less than that of )). Thus, ? = @ 1 + @ 2 +2 = @ +1.
10
VM
Exercise 10.2. The centre of a graph ⌧ is the set of all vertices of ⌧ with minimum eccen-
tricity –i.e. the set of all vertices E of ⌧ with ecc E = rad E. Show that every tree has a centre
consisting of either exactly one vertex or exactly two adjacent vertices.
Hint: Observe that deleting all pendant vertices of a tree results in a new tree with the same centre.
11 Blocks
A cutvertex of a graph is a vertex whose removal increases the number of components,i.e.
a vertex E of ⌧ such that ⌧ E has more components than ⌧. If ⌧ is connected, we can
equivalently say that E is a cutvertex if ⌧ E is disconnected. Similarly, a cutedge or bridge
of a graph whose removal increases the number of components. A nonseparable graph is
a connected, non-trivial graph with no cutvertices. A maximal nonseparable subgraph of a
graph is a block of the graph. A nonseparable graph is itself said to be a block as well.
Example 11.1. The graph shown below has 6 blocks and 3 cutvertices (E 1 , E2 , E3 ).
v1 v3
v2
v1 v1 v2 v2 v3 v3
v2 v3
11
VM
Theorem 11.2. If ⌧ is a connected graph, and E is any vertex of ⌧, then the following are
equivalent:
(i) E is a cutvertex of ⌧.
(ii) There exist vertices D and F of ⌧, distinct from E, such that every D-F path passes through
E.
(iii) There exists a partition of +(⌧) E into two non-empty subsets * and , such that for all
D 2 * and F 2 ,, every D-F path passes through E.
Proof. (i) =) (iii). Since E is a cutvertex, the graph ⌧ E is disconnected,i.e. it has two or
more components. Let * be the set of all the vertices in any one of the components, and let
, be the set of all the remaining vertices of ⌧ E. Clearly, {* , ,} is a partition of +(⌧) E.
Now, if D 2 * and F 2 ,, then D and F are in different components of ⌧ E, which implies
that any path from D to F must pass through E.
(iii) =) (ii) is obvious as the latter is a special case of the former.
(ii) =) (i). Consider the graph ⌧ E. As every D-F path passes through E, none of them is
present in ⌧ E, and therefore ⌧ E is disconnected. Hence, E is a cutvertex of ⌧. É
12 Line Graphs
Let ⌧ be a graph with at least one edge. The line graph of ⌧ is the graph !(⌧) whose vertex
set is the edge set of ⌧, in which two vertices 4 and 5 are adjacent if the edges 4 and 5 of ⌧
are adjacent.
Example 12.1. Fig. 2 shows a graph ⌧ with eight edges and and its line graph !(⌧).
e1
e1
e2
e3 e2
e7 e3
e7
e4 e5
e4 e5
e8
e8
e6
e6
(a) ⌧ (b) !(⌧)
If D and E are edges joined by an edge 4 in ⌧, then in !(⌧), the vertex 4 will be adjacent
to all the vertices corresponding to the edges of ⌧ other than 4 that are incident with D and
E (see Fig. 3). Thus, deg!(⌧) 4 = deg⌧ D + deg⌧ E 2.
’ ✓deg E ◆
⌧
Theorem 12.2. For any graph ⌧ of size < 1, its line graph !(⌧) has order < size .
2
E2+(⌧)
Proof. By definition, the vertices of !(⌧) are the edges of ⌧, and hence the order of !(⌧) is
the size of ⌧, <.
12
VM
e1 e4
e1 e4
e2 e e2 e
u v
e3 e5
e3 e5
G L(G)
As the summation is over the edges of ⌧, each vertex E of ⌧ appears exactly deg E times in
the above summation, which can therefore be written as
1 ’ ’ ✓deg E ◆
⌧
(deg⌧ E)(deg⌧ E 1) = . É
2 2
E2+(⌧) E2+(⌧)
13 Adjacency Matrices
The adjacency matrix of a graph ⌧ of order =, with vertex set + = {E1 , . . . , E = }, is the = ⇥ =
matrix = (⌧) whose (8, 9)-entry is
(
1, E8 ⇠ E 9
0 89 =
0, E8 / E 9 .
v2 v7
v3 v6
v4 v5
13
VM
is
20 13
6 7
1 1 1 1 1
61 07
6 7
0 1 0 0 0
61 17
6 7
1 0 1 1 1
= 61 07 .
61 7
0 1 0 0 0
6 07
61 077
0 1 0 0 0
6 0 1 0 0 0
61 075
4 0 1 0 0 0
Observe that, as the graphs we discuss are simple graphs and therefore have no self-loops
on vertices, no vertex is adjacent to itself –i.e. 0 88 = 0 for all 8 = 1, . . . , =. Also, since the
graphs are undirected, E 8 ⇠ E 9 if and only if E 9 ⇠ E 8 –i.e. 0 89 = 0 98 . Thus, we have the
following observation.
Observation 13.2. The adjacency matrix of a (simple, undirected) graph is a symmetric, zero-
diagonal, (0, 1)-matrix.
In the 8þrow of the adjacency matrix, for each 9, the 9þentry is 1 if E 9 is adjacent to E 8 ,
and 0 otherwise. That is, the number of 1s in the 8þrow is the number of vertices adjacent
to E 8 , or in other words, the degree of E 8 . Thus, the row sums of are the vertex degrees.
Observe that is the vector of row sums, where is the vector (of suitable size) with all
entries equal to 1. For instance, with the matrix given in Example 13.1,
20 13 21 3 26 3
6 7 6 7 6 7
1 1 1 1 1
61 07 61 7 62 7
6 7 6 7 6 7
0 1 0 0 0
61 17 61 7 66 7
6 7 6 7 6 7
1 0 1 1 1
= 61 07 61 7 = 62 7 .
61 7 61 7 62 7
0 1 0 0 0
6 07 6 7 6 7
61 077 61 7 62 7
0 1 0 0 0
6 0 1 0 0 0 6 7 6 7
61 075 61 7 62 7
4 0 1 0 0 0 4 5 4 5
From the Handshaking Lemma and the preceding observation, it follows that the sum of all
entries of is twice the number of edges of the graph.
Exercise 13.1. Show that the (8, 9)-entry of 2 is the number of walks of length 2 from E 8 to
E 9 . Hence show that tr( 2 ) = 2|⇢(⌧)|.
2 Õ=
Hint: Recall that if is any = ⇥ = matrix, then the (8, 9)-entry of is 0 0 . As
:=1 8 : : 9
is a (0 , 1)-matrix, each term in this summation is 1 or 0, with the former if and only if
0 8 : = 0 : 9 = 1. What does this imply about the vertices E 8 , E : , and E 9 ? Then, as : varies from 1 to = , what does the value of the sum imply about E 8 and E 9 ?
The following result (which generalises the statement in Exercise 13.1) shows that the
adjacency matrix can be used to obtain certain information about walks in the graph.
Theorem 13.3. Let be the adjacency matrix of a graph ⌧ with vertex set {E1 , . . . , E = }. Then
the (8, 9)-entry of < , for any positive integer <, is the number of walks of length < from E 8 to
E9.
Proof. We prove the result by induction on <. For < = 1, the (8, 9)-entry of 1 = is 0 89 ,
which is 1 if and only if E 8 is adjacent to E 9 ,i.e. if and only if there is a walk of length 1
(namely, an edge) from E 8 to E 9 . Thus, the result holds for < = 1.
Now suppose, for the sake of induction, that the result holds for some < 1, and consider
<+1 . The (8, 9)-entry of <+1 is
’
=
<+1 <
( )89 = ( )8 : 0 : 9 .
:=1
14
VM
First, note that 0 : 9 = 1 if and only if E : ⇠ E 9 . Therefore, the above sum is equal to the sum
of all ( < )8 : where E : ⇠ E 9 . Now, by the induction hypothesis, ( < )8 : is the number of walks
of length < from E 8 to E : . If E 9 is adjacent to E 9 , then each walk of length < from E 8 to E : ,
together with the edge from E 9 to E 9 , forms a walk of length < + 1 from E 8 to E 9 . Thus, for
each : such that E : ⇠ E 9 , ( < )8 : 0 : 9 = ( < )8 : is the number of walks of length < + 1 from E 8
to E 9 that pass through :. Summing over all :, this gives the total number of walks of length
< + 1 from E 8 to E 9 . Hence the result follows by induction. É
Theorem 13.4. Let be the adjacency matrix of a graph ⌧ with vertex set {E1 , . . . , E = }. Then
(i) tr 2 = 2|⇢(⌧)|
(ii) tr 3 = 623 (⌧)
where 23 (⌧) denotes the number of triangles in ⌧.
Proof. We know that ( <) is the number of walks of length < from E 8 to E 9 .
89
(i) Hence, the 8 th diagonal entry of 2 , viz. ( 2 )88 , is the number of walks of length 2 from
E 8 to itself. Any walk of length 2 from E 8 to itself is of the form E 8 E 9 E 8 , where E 9 is a
vertex adjacent to E 8 . Thus, the number of suchÕwalks is equal to the number of ver-
tices adjacent to E 8 ,i.e. deg E 8 . Hence, tr 2 = =8=1 deg E 8 = 2|⇢(⌧)|, by Handshaking
Lemma.
(ii) Similarly, ( 3 )88 is the number of walks of length 3 from E 8 to itself. Any such walk is of
the form E 8 E 9 E : E 8 , which implies that E 8 , E 9 , and E : form a triangle in ⌧. Moreover, each
such triangle corresponds to two distinct walks from E 8 to itself, when traversed in the
two opposite directions. Thus, ( 3 )88 is twice the number of triangles having E 8 as one
of its vertices. Therefore, tr 3 is 623 (⌧), since each triangle contains three vertices,
each of which counts the triangle twice in the sum tr 3 . É
14 Incidence Matrices
Consider an (=, <)-graph ⌧ having vertex set {E1 , . . . , E = } and edge set {41 , . . . , 4 < }. The
incidence matrix of ⌧ is the = ⇥ < matrix ⌫ = ⌫(⌧) whose (8, 9)-entry is 1 if the vertex E 8 is
incident with the edge 4 8 , and 0 otherwise.
Example 14.1. The incidence matrix of the graph
v2 v3
e1 e7
v1 e2 e5 e6 v4
e4
e3
v6 e8 v5
is
21 03
6 7
1 1 0 0 0 0
61 07
6 7
0 0 1 1 0 0
60 07
⌫=6 7.
1 0 0 0 1 1
60 07
60 177
0 0 0 0 0 1
6 0 0 0 1 1 0
60 175
4 0 1 1 0 0 0
15
VM
Each column of the incidence matrix corresponds to an edge of the graph, and the only
non-zero entries in the column correspond to the end-vertices of the edge – thus, each column
contains exactly two 1s. In a simple graph, there is at most one edge between a given pair of
vertices, and hence no two columns of the incidence matrix can be equal. We therefore have
the following observation.
Observation 14.2. The incidence matrix of a (simple, undirected) graph is a (0, 1)-matrix in
which every column has exactly two 1s, and no two columns are equal.
Theorem 14.3. If ⌫ is the incidence matrix of a graph ⌧, then the adjacency matrix of its line
graph !(⌧) is
(!(⌧)) = ⌫) ⌫ 2
where is the identity matrix of order |⇢(⌧)|.
Proof. Let ⌧ be an (=, <)-graph with edge set ⇢ = {41 , . . . , 4 < }. The incidence matrix ⌫ =
⌫(⌧) is of order = ⇥ <, and therefore ⌫) ⌫ 2 (say) is of order < ⇥ <.
Observe that the (8, 9) entry of ⌫) ⌫ is the dot product of the 8 th and 9 th columns of ⌫. As
each column of ⌫ has exactly two non-zero entries, both equal to 1, the (8, 8) entry of ⌫) ⌫ is
2, and therefore the diagonal entries of ⌫) ⌫ 2 are all zero.
For 8 < 9, the dot product of the 8 th and 9 th columns of ⌫ will be 1 if the edges 4 8 and 4 9
are adjacent (i.e. have one vertex in common), and 0 otherwise – note that the dot product
cannot be 2, as no two distinct columns of ⌫ can be equal. Thus, for 8 < 9, the (8, 9)-entry of
⌫) ⌫, which is equal to the (8, 9) entry of ⌫) ⌫ 2 , is 1 if and only if the edges 4 8 and 4 9 are
adjacent in ⌧, or equivalently, the vertices 4 8 and 4 9 of !(⌧) are adjacent. Thus, ⌫) ⌫ 2 is
the adjacency matrix of ⌧. É
15 Dijkstra’s Algorithm
Let ⌧ be a directed graph on = vertices E1 , . . . , E = , in which each (directed) edge has a
positive weight attached to it (say, representing the cost of traversing that edge). Let , be
the weighted adjacency matrix of ⌧, defined as follows. , is an = ⇥ = matrix with rows and
columns indexed by the vertices of ⌧, and having (8, 9)-entry
8
>
>
< 0,
> 8=9
F 89 = Weight of the edge (E 8 , E 9 ), E 8 ⇠ E 9
>
>
> 1,
: E8 / E 9 .
Dijkstra’s algorithm is a procedure to determine the shortest paths (and hence distances)
from a given source vertex B of ⌧ to all the other vertices.
The input to the algorithm is the set of vertices + and the weighted adjacency matrix
,. Initially, the algorithm takes the weights of the edges from B to the other vertices as the
tentative best distances to those vertices. It also maintains a set of vertices to which the
shortest paths from B have been found (so that no further improvement is possible), and a
set * of vertices to which shorter paths may yet be found, passing through some vertex in
. In each step, the vertex C 2 * with minimum tentative best distance is selected – it is
guaranteed that no shorter path exists from B to this vertex (since any such path would have
to pass through some other vertex of *, but the distances to such a vertex is larger than the
distance to C). This vertex C is removed from * and added to , and then for each vertex D
16
VM
remaining in *, the distance from B to D through C is compared with the current best distance
to D. If the former is found to be smaller, the best distance to D is updated to that value
and C is marked as the vertex through which D is to be reached in the shortest path – this is
indicated by tree(D) in the algorithm. This procedure is repeated until there is only vertex
remaining in * (i.e. until |*| = 1).
Example 15.1. In the graph shown below, find the shortest paths from ⌫ to all the other
vertices.
⌫ ⇠ ⇡ ⇢
2 0 7 1 1 6 3
6 7
6 1 0 5 10 1 7
6 7
⌫
,= 6 12 6 0 3 1 7 .
6 7
⇠
6 11 1 8 0 1 7
6 4 5 1 6 0 75
⇡
⇢ 4
The results of applying the algorithm are tabulated below and the tree of shortest paths
is also shown.
17
VM
⇠ ⇡ ⇢
⌫(0) 1⌫ 5⌫ 10⌫ 1⌫
⇠(5) 17⇠ _ 8⇠ 1⌫
⇡(8) 17⇠ _ _ 1⌫
(17) _ _ _ 23
⌫ 17⇠ 5⌫ 8⇠ 23
16 Prim’s Algorithm
Let ⌧ be a weighted, undirected, connected graph with positive edge weights. A minimal
spanning tree of ⌧ is a spanning tree ) of ⌧ such that the sum of the weights of its edges is
minimum among all the spanning trees of ⌧.
Example 16.1. Apply Prim’s algorithm to the graph given below to obtain a minimal spanning
tree. Take E1 as the initial vertex.
v3 2 v4
8
v2
11
2 4
5
3
v1 v5
1 7
3
2
v8
6
v7 9 v6
18
VM
v2
3
v1 v5
1 7
3
2
v8
v7 v6
19