Representing Graphs and Graph
Isomorphism
Course Code: 00090 Course Title: Discrete Mathematics
Dept. of Computer Science
Faculty of Science and Technology
Lecturer No: 16 Week No: 9 Semester:
Lecturer: Pritam Khan Boni,
[email protected]Lecture Outline
Representing Graphs and Graph Isomorphism (8.3)
• Graph Representation:
Adjacency lists
Adjacency matrices
Incidence matrices
• Graph Isomorphism
Objectives and Outcomes
• Objectives: To understand three different representation of
a Graph, to understand graph invariants and graph
isomorphism.
• Outcomes: This students are expected to be able to
represent a graph using adjacency list, adjacency matrix,
and incidence matrix; be able to determine whether two
graphs are isomorphic.
Representing Graphs
• One way to represent a graph without multiple edges is to list all
the edges of the 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.
• Adjacency Lists: A table with 1 row per vertex, listing its adjacent
vertices.
• Directed Adjacency Lists: A table with 1 row per node, listing the
terminal nodes of each edge incident from that node.
Representing a Graph with an Adjacency List
• EXAMPLE 1: Use adjacency lists to describe the
simple graph given in Figure 1.
Representing a Graph with an Adjacency List
• EXAMPLE 2: Represent the directed graph shown in Figure 2
by listing all the vertices that are the terminal vertices of
edges starting at each vertex of the graph.
Representing Graphs using Matrices
• Two types of matrices commonly used to represent
graphs –
1) Adjacency matrix
2) Incidence matrix
• Adjacency matrix: A matrix representing a graph
using the adjacency of vertices.
• Incidence matrix: A matrix representing a graph using
the incidence of edges and vertices.
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 of G, with respect to this listing of the
vertices, is the n x 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
aij = 1 if {vi, vj} is an edge of G,
0 otherwise
Example 3: Representing a graph using an Adjacency Matrix
Given an Adjacency matrix, draw the graph
• Example 4 : Draw a graph with the adjacency matrix below.
0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0
Solution:
a b
d c
Adjacency matrices
• Adjacency matrix can also be used to represent
undirected graphs with loops and with multiple
edges.
– A loop at the vertex ai is represented by 1 at the (i,j)th
position of the adjacency matrix.
– When multiple edges are present, the adjacency matrix is
no longer zero-one matrix, because the (i,j)th entry of this
matrix equals the number of edges that are associated to
{ai ,aj }
– All undirected graphs, including multigraphs and
pseudographs, have symmetric adjacency matrices
Adjacency matrices
• Example : What’s the adjacency matrix of the following
graph?
a b
c d
Adjacency matrices
a b
c d
Solution: 0 2 1 0
2 2 1 0
1 1 0 0
0 0 0 1
Practice at Home
• Example 5 : Use an adjacency matrix to represent the
pseudograph shown in Figure 5.
Adjacency matrices for
Directed Graphs
• Adjacency matrices can also be used to represent
directed multigraphs.
– However, such matrices are not zero-one matrices when
there are multiple edges in the same direction connecting
two vertices
• In the adjacency matrix for a directed graph, aij
equals the number of edges that are associated to
(vi ,vj ).
Adjacency matrices for directed graphs
Example : What is the adjacency matrix?
a d c
b
a d c
Solution:
0 3 0 1
0 1 2 0
0 1 2 0
0 0 0 0
Incidence matrices
• Incidence matrix: A matrix representing a graph using the
incidence of edges and vertices.
• 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 x m matrix, M = [mij], where
mij = 1 when edge ej is incident with vi ,
0 otherwise
Example 6: Representing a graph with an Incidence Matrix
Example 7 : Representing a graph with an Incidence
Isomorphism of Graphs
• Definition 1: 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 G1 , for all a and b in V1 .
Such a function f is called an isomorphism.
– When two simple graphs are isomorphic, there is a one-to-one
correspondence between vertices of the two graphs that preserves
the adjacency relationship
– Two graphs are isomorphic iff they are identical except for their node
names
– Isomorphism of simple graphs is an equivalence relation
Isomorphism of Graphs
• Intuitively, two graphs are isomorphic if can bend,
stretch and reposition vertices of the first graph,
until the second graph is formed. Etymologically,
isomorphic means “same shape”.
e.g.: Can twist or relabel:
to obtain:
Example 8
• Show that the graphs G=(V,E) and H=(W,F) are isomorphic.
u1 u2 v1 v2
u3 u4 v3 v4
G H
Solution of Example 8
• The function f with f(u1) = v1, f(u2) = v4, f(u3) = v3, and
f(u4)= v2 is a one-to-one correspondence between V
and W. To see that this correspondence preserves
adjacency, note that adjacent vertices in G are u1 and
u2, u1 and u3, u2 and u4, and each of the pairs f(u1)= v1
and f(u2) = v4, f(u1)= v1 and f(u3)= v3,
• Again f(u2)= v4 and f(u4)= v2, and f(u3)= v3 and f(u4)= v2
are adjacent in H.
• So, the graphs G and H are isomorphic.
Isomorphism of Graphs
• It is often difficult to determine whether two simple graphs are
isomorphic.
• Sometimes it is not hard to show that two graphs are not isomorphic.
• A property preserved by isomorphism of graph is called a graph invariant.
• Isomorphic simple graphs must have –
– The same # of vertices
– The same # of edges
– The degrees of the vertices must be the same and degrees of adjacent
vertices must be same
– Same length of simple circuit(s), if any
Example 9
• Show that the following two graphs G and H are not
isomorphic.
b
b
a c a c
e d e d
G H
Solution of Example 9
• Solution : Both G and H have five vertices and six
edges. However, H has a vertex of degree one,
namely e, whereas G has no vertices of degree one.
It follows that G and H are not isomorphic.
• There are other answers too!
What are the other answers?
Isomorphism of Graphs
• Note: The number of vertices, the number of edges,
and the number of vertices of each degree are all
invariants 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. There are NO useful sets of invariants
currently known that can be used to determine
whether simple graphs are isomorphic.
Graph Isomorphism : Negative Examples
Q1: Why are the following graphs not isomorphic?
u2 v2
u3
u1 v1 v3
u5 u4 v4
Graph Isomorphism : Negative Examples
A1: 1st graph has more vertices than 2nd. So, the graphs
are not isomorphic. What are other answers?
Q2: Why are the following graphs not isomorphic?
u2 v2
u3 v3
u1 v1
u5 u4 v5 v4
Graph Isomorphism : Negative Examples
A2: 1st graph has more edges than 2nd. What are other
answers?
Q3: Why are the following graphs not isomorphic?
u2 v2
u3 v3
u1 v1
u5 u4 v5 v4
Graph Isomorphism : Negative Examples
A3: 2nd graph has vertex of degree 1, 1st graph doesn't.
So, the graphs are not isomorphic. What are other
answers?
Q4: Why are the following graphs non-isomorphic?
u1 u2 u3 u4 u5 u6 v1 v2 v3 v4 v5 v6
u7 u8 u9 v7 v8 v9
Graph Isomorphism : Negative Examples
• A4: 1st graph has 2 vertices of degree 1, whereas
the 2nd graph has 3 vertices of degree 1.
So, the graphs are not isomorphic.
What are other answers?
Practice @ Home
• Example 10
• Example 11
• Relevant Exercises from your text book
Books
• Rosen, K. H., & Krithivasan, K. (2012). Discrete mathematics and its
applications: with combinatorics and graph theory. Tata McGraw-Hill
Education. (7th Edition)
• Liu, C. L. (1986). Elements of discrete mathematics. Tata McGraw-Hill Education.
References
1. Discrete Mathematics, Richard Johnsonbaugh, Pearson education, Inc.
2. Discrete Mathematical Structures, Bernard Kolman, Robert C. Busby, Sharon Ross,
Prentice-Hall, Inc.
3. SCHAUM’S outlines Discrete Mathematics(2nd edition), by Seymour Lipschutz, Marc
Lipson
• An online tutorial https://www.geeksforgeeks.org/graph-and-its-representations/
• Another online tutorial https://www.gatevidyalay.com/graph-isomorphism/
• Personal blog http://www.rogerfhouse.com/math-articles/graph-isomorphism.pdf