Graph (cont’d)
Representing Graphs and Graph
Isomorphism
• Sometimes, two graphs have exactly the same form, in the sense that there is a one-to-one correspondence between their vertex sets that preserves edges. In such a case, we say that the two graphs are isomorphic.
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
Solution•Use table to list vertices adjacent to each of the vertices of the graph.
An Edge List for a Simple Graph.
a
Vertex Adjacent Vertices
b
c
d
e
b, c, e
a
a, d, e
c, e
a, c, d
Example• Draw the directed graph from the table.
An Edge List for a Directed Graph.Initial Vertex Terminal Vertices
abcde
b, c, d, eb, da, c, e-b, c, d
Solution
Adjacency matrices
• Graphs can be represented using matrices.
• Two types of matrices commonly used to represent graphs will be presented.
• One is based on the adjacency of vertices, and the other is based on incidence of vertices and edges.
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 thislisting 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 entrywhen they are not adjacent. In other words, if its adjacencymatrix is A = [aij], then
aij =1 if {vi, vj} is an edge of G,
0 otherwise.
• The adjacency matrix of a simple graph is symmetric, that is
aij = aji
since both of these entries are 1 when vi and vj are adjacent, and both are 0 otherwise. Furthermore, since a simple graph has no loops, each entry aii , i = 1, 2, 3, …, n is 0
Example
• Use an adjacency matrix to represent the graph
Solution
a b c d
a 0 1 1 1
b 1 0 1 0
c 1 1 0 0
d 1 0 0 0
Example
• Draw a graph with the adjacency matrix
0110
1001
1001
0110
Solutiona b
cd
• 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, aj}.
• All undirected graphs, including multigraphs and pseudographs, have symmetric adjacency matrices.
Example
• Use an adjacency matrix to represent the pseudograph
Solution
a b c d
a 0 3 0 2
b 3 0 1 1
c 0 1 1 2
d 2 1 2 0
• Use zero-one matrices to represent directed graphs. • The matrix for a directed graph G = (V, E). A = [aij] is the adjacency matrix for the directed graph with respect to this listing of the vertices, then
aij = 1 if (vi, vj) is an edge of G,
0 otherwise.
Note that an adjacency matrix of a graph is based on the orderingchosen for the vertices. Hence, there are as many as n! differentadjacency matrices for a graph with n vertices, since there are n!different orderings of n vertices.
• The adjacency matrix for a directed graph does not have to be symmetric, since there may not be an edge from aj to ai when there is an edge from ai to aj
• Adjacency matrices can also be used to represent directed multigraphs. 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 multigraph, aij equals the number of edges that are associated to (vi, vj)
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, …, vnare the vertices and e1, e2, …, em are the edges of G.
• 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
• Represent the graph with an incidence matrix.
Solution
5
4
3
2
1
v
v
v
v
v
e1 e2 e3 e4 e5 e6
• Incidence matrices can also be used to represent multiple edges and loops.
1 1 0 0 0 01 1 0 0 0 0
0 0 1 1 0 1
0 0 0 0 1 1
1 0 1 0 0 0
0 1 0 1 1 0
Example
• Represent the pseudograph show in Figure using an incidence matrix.
Solution
5
4
3
2
1
v
v
v
v
v
e1 e2 e3 e4 e5 e6 e7 e8
1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0
0 1 1 1 0 1 1 0
0 0 0 1 1 0 0 0
0 0 0 0 0 0 1 1
0 0 0 0 1 1 0 0
Isomorphism of graphs
Definition• The simple graph G1 = (V1, E1) and G2 = (V2, E2) are isomorphic if there is a one-to-one and onto function ffrom V1 to V2 with the property that a and b are adjacent in G1 if and only if f(a) and f(b) are adjacent in G2, for all a and b in V1. Such a function f is called an isomorphism.
Example
• Show that the graphs G = (V, E) and H = (W, F) are isomorphic.
SolutionThe functionf(u1) = v1 f(u2) = v4f(u3) = v3 f(u4) = v2is a one-to-one correspondence between V and W.
Adjacent vertices in G are:u1 and u2 u1 and u3u2 and u4 u3 and u4
Adjacent vertices in G are:f(u1) = v1 and f(u2) = v4 f(u1) = v1 and f(u3) = v3f(u2) = v4 and f(u4) = v2 f(u3) = v3 and f(u4) = v2
• It is often difficult to determine whether two simple graphs are isomorphic.
• There are n! possible one-to-one correspondences between the vertex sets of two simple graphs with nvertices. • Testing each such correspondence to see whether it preserves adjacency and nonadjacency is impractical if n is at all large.
• Two simple graphs are not isomorphic by showing that they do not share a property that isomorphic simple graphs must both have. • An invariant with respect to isomorphism of simple graphs. For instance, isomorphic simple graphs must have
• The same number of vertices. • The same number of edges • The degrees of the vertices in isomorphic simple graphs must be the same.
Example
• Show that the graphs are not isomorphic.
SolutionGraph G :
No. of vertices = 5No. of edges = 6degree = 1 ไม่มี
Graph H :No. of vertices = 5No. of edges = 6degree = 1 จุด e
Not isomorphic.
Example
• Determine whether the graphs are isomorphic.
Solution
Graph G :No. of vertices = 8No. of edges = 10degree = 2 มี 4 จุด degree = 3 มี 4 จุด
Graph H :No. of vertices = 8No. of edges = 10degree = 2 ม ี4 จุด degree = 3 ม ี4 จุด
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.
Example
• Determine whether the graphs G and H are isomorphic.
Solution
Graph G :No. of vertices = 6No. of edges = 7degree = 2 มี 4 จุด degree = 3 มี 2 จุด
Graph H :No. of vertices = 6No. of edges = 7degree = 2 ม ี4 จุด degree = 3 ม ี2 จุด
We now will define a function f and then determine whether it
is an isomorphism. Since deg(u1) = 2 and since u1 is not
adjacent to any other vertex of degree 2, the image of u1 must
be either v4 or v6, the only vertices of degree 2 in H not
adjacent to a vertex of degree 2. We arbitrarily set f(u1) = v6.
[If we found that this choice did not lead to isomorphism, we
now then try f(u1) = v4.] Since u2 is adjacent to u1, the
possible images of u2 are v3 and v5. We arbitrarily set f(u2) =
v3. Continuing in this way, using adjacency of vertices and
degrees as a guide, we set f(u3)= v4, f(u4) = v5, f(u5) = v1,
and f(u6) = v2. We now have a one-to-one correspondence
between the vertex set of G and the vertex set of H, namely:
f(u1)= v6, f(u2) = v3, f(u3)= v4, f(u4) = v5, f(u5) = v1, f(u6)
= v2.
To see whether f preserves edges, we examine the adjacency
matrix of G,
u1 u2 u3 u4 u5 u6
u1 0 1 0 1 0 0
u2 1 0 1 0 0 1
Ag = u3 0 1 0 1 0 0
u4 1 0 1 0 1 0
u5 0 0 0 1 0 1
u6 0 1 0 0 1 0
And the adjacency matrix of H with the rows and columns
labeled by the images of the corresponding vertices in G,
v6 v3 v4 v5 v1 v2
v6 0 1 0 1 0 0
v3 1 0 1 0 0 1
Ah = v4 0 1 0 1 0 0
v5 1 0 1 0 1 0
v1 0 0 0 1 0 1
v2 0 1 0 0 1 0
Since Ag = Ah, it follows that f preserves edges. We conclude
that f is an isomorphism, so that G and H are isomorphic.