Lecture 12
Representing graphs
One way to represent a graph without multiple edges is to list all the edges of this graph. Another
way to represent a graph with no multiple edges is to use adjacency lists, which specify the vertices
that are adjacent to each vertex of the graph.
Example. Use adjacency lists to describe the simple graph given in Figure below.
Solution:
An edge list for a simple graph
Vertex Adjacent vertices
a b, c, e
b a
c a, d, e
d c, e
e a, c, d
Example. Represent the directed graph by listing all the vertices that are the terminal vertices of
edges starting at each vertex of the graph.
Solution:
An edge list for a directed graph
Initial vertex Terminal vertex
a b, c, d, e
b b, d
c a, c, e
d
e b, c, d
Adjacency matrices
Suppose that G (V , E) is a simple graph where | V | n . Suppose that the vertices of G are listed
arbitrarily as v1 , v2 , ..., vn . The adjacency matrix A (or AG) of G, with respect to this listing of the
vertices, is the n n zero-one matrix with 1 as its (i, j)th entry when vi and vj are adjacent, and 0 as its
(i, j)th entry when they are not adjacent. In other words, if its adjacency matrix is A [ aij ] , then
1 if {vi , v j } is an edge of G
aij .
0 otherwise
Example. Use an adjacency matrix to represent the graph shown in Figure below.
0 1 1 1
1 0 1 0
Solution: We order the vertices as a, b, c, d. The matrix representing this graph is .
1 1 0 0
1 0 0 0
0 1 1 0
1 0 0 1
Example. Draw a graph with the adjacency matrix with respect to the ordering of
1 0 0 1
0 1 1 0
vertices a, b, c, d.
Solution:
Adjacency matrices can also be used to represent undirected graphs with loops and with multiple
edges. A loop at the vertex ai is represented by a 1 at the (i, i)th position of the adjacency matrix.
When multiple edges are present, the adjacency matrix is no longer a zero-one matrix, since the
(i, j)th entry of this matrix equals the number of edges that are associated to {ai , a j } .
Example. Use an adjacency matrix to represent the pseudograph shown in Figure below.
0 3 0 2
3 0 1 1
Solution: The adjacency matrix using the ordering of vertices a, b, c, d is .
0 1 1 2
2 1 2 0
Incidence matrices
Another common way to represent graphs is to use incidence matrices. Let G (V , E) be an
undirected graph. Suppose that v1 , v2 ,..., vn are the vertices and e1 , e2 ,..., em are the edges of G. Then
the incidence matrix with respect to this ordering of V and E is the n m matrix M [ mij ] , where
1 when edge e j is incident with vi
mij .
0 otherwise
Example. Represent the graph shown in Figure below with an incidence matrix.
Solution: e1 e2 e3 e4 e5 e6
v1 1 1 0 0 0 0
v2 0 0 1 1 0 1
v3 0 0 0 0 1 1
v4 1 0 1 0 0 0
v5 0 1 0 1 1 0
Incidence matrices can also be used to represent multiple edges and loops. Multiple edges are
represented in the incidence matrix using columns with identical entries, since these edges are
incident with the same pair of vertices. Loops are represented using a column with exactly one entry
equal to 1, corresponding to the vertex that is incident with this loop.
Example. Represent the pseudograph shown in Figure below using an incidence matrix.
Solution: e1 e2 e3 e4 e5 e6 e7 e8
v1 1 1 1 0 0 0 0 0
v2 0 1 1 1 0 1 1 0
v3 0 0 0 1 1 0 0 0
v 4 0 0 0 0 0 0 1 1
v5 0 0 0 0 1 1 0 0
Isomorphism of graphs
The simple graphs G1 (V1 , E1 ) and G2 (V2 , E2 ) are isomorphic if there is a one-to-one and onto
function f from V1 to V2 with the property that a and b are adjacent in G1 iff f(a) and f(b) are adjacent
in G2, for all a and b in V1. Such a function f is called an isomorphism. In other words, when two
simple graphs are isomorphic, there is a one-to-one correspondence between vertices of the two
graphs that preserves the adjacency relationship.
Example. Show that the graphs G (V , E) and H (W , F ) are isomorphic.
Solution: The function f with f (u1 ) v1 , f (u2 ) v4 , f (u3 ) v3 and f (u4 ) v2 is an isomorphism.
Example. Show that the graph G and H are not isomorphic.
Solution: Both G and H have five vertices and six edges. However, H has a vertex of degree 1,
namely e, whereas G has no vertices of degree 1. It follows that G and H are not isomorphic.
The number of vertices, the number of edges, and the degrees of the vertices are all variants under
isomorphism. If any of these quantities differ in two simple graphs, these graphs cannot be
isomorphic. However, when these invariants are the same, it does not necessarily mean that the two
graphs are isomorphic.
Example. Determine whether the graphs G and H are isomorphic.
Solution: The graphs G and H have 8 vertices and 10 edges. They also both have 4 vertices of degree
2 and 4 of degree 3. Since these invariants all agree, it is still conceivable that these graphs are
isomorphic. However, G and H are not isomorphic. To see this, note that since deg(a) = 2 in G, a
must correspond to either t, u, x or y in H, since these are the vertices of degree 2 in H. However,
each of these four vertices in H is adjacent to another vertex of degree 2 in H, which is not true for a
in G.
To show that a function f from the vertex set of a graph G to the vertex set of a graph H is an
isomorphism, we need to show that f preserves edges. One helpful way to do this is to use adjacency
matrices. In particular, to show that f is an isomorphism, we can show that the adjacency matrix of G
is the same as the adjacency matrix of H, when rows and columns are labeled to correspond to the
images under f of the vertices in G that are the labels of these rows and columns in the adjacency
matrix of G.
Paths
A path of length n from u to v, where n is a positive integer, in an undirected graph is a sequence of
edges e1 , e2 ,..., en of the graph such that f (e1 ) {x0 , x1}, f (e2 ) {x1 , x2 },..., f (en ) {xn1 , xn }, where
x0 u and xn v . When the graph is simple, we denote this path by its vertex sequence x0 , x1 ,..., xn
(since listing these vertices uniquely determines the path). The path is a circuit if it begins and ends
at the same vertex, that is, if u = v. The path or circuit is said to pass through or traverse the vertices
x1 , x2 ,..., xn1 . A path or circuit is simple if it does not contain the same edge more than once.
Example.
In this simple graph a, d, c, f, e is a simple path of length 4, since {a, d}, {d, c}, {c, f} and {f, e} are
all edges. However, d, e, c, a is not a path, since {e, c} is not an edge. Note that b, c, f, e, b is a
circuit of length 4 since {b, c}, {c, f}, {f, e} and {e, b} are edges, and this path begins and ends at b.
The path a, b, e, d, a, b, which is of length 5, is not simple since it contains the edge {a, b} twice.
A path from a to b in a directed graph G is a sequence of one or more edges ( x0 , x1 ) , ( x1 , x2 ) ,
( x2 , x3 ) , …, ( xn1 , xn ) in G, where x0 a and xn b , that is, a sequence of edges where the
terminal vertex of an edge is the same as the initial vertex in the next edge in the path. This path is
denoted by x0 , x1 , x2 ,..., xn1 , xn and has length n. A path that begins and ends at the same vertex is
called a circuit or cycle.
A path of length n from u to v in a directed multigraph is a sequence of edges e1 , e2 ,..., en of the
graph such that f (e1 ) ( x0 , x1 ), f (e2 ) ( x1 , x2 ),..., f (en ) ( xn1 , xn ), where x0 u and xn v .
When there are no multiple edges in the graph, this path is denoted by its vertex sequence
x0 , x1 , x2 ,..., xn . A path or circuit is called simple if it does not contain the same edge more than once.
Connectedness in undirected graphs
An undirected graph is called connected if there is a path between every pair of distinct vertices of
the graph.
Example.
The graph G is connected, since for every pair of distinct vertices there is a path between them.
However, the graph H is not connected. For instance, there is no path in H between vertices a and d.
Theorem 1. There is a simple path between every pair of distinct vertices of a connected undirected
graph.
Proof: Let u and v be two distinct vertices of a connected undirected graph G = (V, E). Since G is
connected, there is at least one path between u and v. Let x0, x1, …, xn, where x0 = u and xn = v, be
the vertex sequence of a path of least length. This path of least length is simple. To see this, suppose
it is not simple. Then xi = xj for some i and j with 0 i j . This means that there is a path from u to
v of shorter length with vertex sequence x0, x1, …, xi–1, xj, …, xn obtained by deleting the edges
corresponding to the vertex sequence xi, …, xj–1.
A graph that is not connected is the union of two or more connected subgraphs, each pair of which
has no vertex in common. These disjoint connected subgraphs are called the connected components
of the graph.
Sometimes the removal of a vertex and all edges incident with it produces a subgraph with more
connected components than in the original graph. Such vertices are called cut vertices (or
articulation points). The removal of a cut vertex from a connected graph produces a subgraph that is
not connected. Analogously, an edge whose removal produces a graph with more connected
components than in the original graph is called a cut edge or bridge.
Example. Find the cut vertices and cut edges in the graph G.
Solution: The cut vertices of G are b, c and e. The removal of one of these vertices (and its adjacent
edges) disconnects the graph. The cut edges are {a, b} and {c, e}. Removing either one of these
edges disconnects G.
Connectedness in directed graphs
A directed graph is strongly connected if there is a path from a to b and from b to a whenever a and
b are vertices in the graph. A directed graph is weakly connected if there is a path between any two
vertices in the underlying undirected graph. That is, a directed graph is weakly connected iff there is
always a path between two vertices when the directions of the edges are disregarded. Clearly, any
strongly connected directed graph is also weakly connected.
Example. Are the directed graphs G and H strongly connected? Are they weakly connected?
Solution: G is strongly connected because there is a path between any two vertices. The graph H is
not strongly connected. There is no directed path from a to b in this graph. However, H is weakly
connected, since there is a path between any two vertices in the underlying undirected graph of H.
The seven bridges of Kenigsberg
The town of Kenigsberg, Prussia (now called Kaliningrad and part of Russia), was divided into four
sections by the branches of the Pregel River. These four sections included the two regions on the
banks of the Pregel, Kneiphof Island, and the region between the two branches of the Pregel. In the
eighteen century seven bridges connected these regions.
The townspeople took long walks through town on Sundays. They wondered whether it was possible
to start at some location in the town, travel across all the bridges without crossing any bridge twice,
and return to the starting point.
The Swiss mathematician Leonhard Euler solved this problem. His solution, published in 1736, may
be the first use of graph theory. Euler studied this problem using the multigraph obtained when the
four regions are represented by vertices and the bridges by edges.
The problem of traveling across every bridge without crossing any bridge more than once can be
rephrased in terms of this model. The question becomes: is there a simple circuit in this multigraph
that contains every edge?
An Euler circuit in a graph G is a simple circuit containing every edge of G.
Theorem 2. A connected multigraph has an Euler circuit iff each of its vertices has even degree.
We can now solve the Kenigsberg bridge problem. Since the multigraph representing these bridges
has four vertices of odd degree, it does not have an Euler circuit. There is no way to start at a given
point, cross each bridge exactly once, and return to the starting point.
Glossary
adjacency matrix – матрица смежности; conceivable – мыслимый; circuit – цепь, кругооборот
to pass through – проходить; cut vertex (articulation point) – разъединяющая вершина
to traverse – пересекать; cut edge (bridge) – разъединяющее ребро
Exercises for Seminar 12
12.1. Use an adjacency list to represent the following graph. Represent each graph with an adjacency
matrix.
12.2. Draw a graph with the following adjacency matrix.
0 0 1 1
0 1 0 0 0 1 0
a) 1 0 1 b)
1 1 0 1
0 1 0
1 1 1 0
12.3. Represent the following graph using an adjacency matrix.
12.4. Use an incidence matrix to represent the graphs in Ex. 12.3.
12.5. Determine whether the following pair of graphs is isomorphic.
12.6. Does each of the following lists of vertices form a path in the following graph?
Which paths are simple? Which are circuits? What are the lengths of those that are paths?
a) a, e, b, c, b b) a, e, a, d, b, c, a c) e, b, a, d, b, e d) c, b, d, a, e, c
12.7. Determine whether the following graph is connected.
12.8. Find all the cut vertices of the following graph.
Exercise for Homework 12
12.9. Use an adjacency list to represent the following graph. Represent each graph with an adjacency
matrix.
12.10. Draw an undirected graph representing by the following adjacency matrix.
1 2 0 1
1 3 2 2 0 3 0
a) 3 0 4 b)
0 3 1 1
2 4 0
1 0 1 0
12.11. Find the adjacency matrix of the following directed multigraph.
12.12. Determine whether the following pair of graphs is isomorphic.
12.13. Does each of the following lists of vertices form a path in the following graph?
Which paths are simple? Which are circuits? What are the lengths of those that are paths?
a) a, b, e, c, b b) a, d, a, d, a c) a, d, b, e, a d) a, b, e, c, b, d, a
12.14. Find all the cut edges of the following graph.
12.15. Find the number of paths from a to e in the directed graph in Ex. 12.13 of length:
a) 2; b) 3; c) 4; d) 5; e) 6; f) 7.