+ All Categories
Home > Documents > Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 ·...

Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 ·...

Date post: 15-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
38
Graph (cont’d)
Transcript
Page 1: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Graph (cont’d)

Page 2: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 3: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 4: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 5: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 6: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 7: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 8: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 9: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

• 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

Page 10: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Use an adjacency matrix to represent the graph

Page 11: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 12: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Draw a graph with the adjacency matrix

0110

1001

1001

0110

Solutiona b

cd

Page 13: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

• 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.

Page 14: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Use an adjacency matrix to represent the pseudograph

Page 15: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 16: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

• 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.

Page 17: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

• 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)

Page 18: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 19: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Represent the graph with an incidence matrix.

Page 20: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 21: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Represent the pseudograph show in Figure using an incidence matrix.

Page 22: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 23: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 24: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Show that the graphs G = (V, E) and H = (W, F) are isomorphic.

Page 25: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 26: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

• 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.

Page 27: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

• 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.

Page 28: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Show that the graphs are not isomorphic.

Page 29: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

SolutionGraph G :

No. of vertices = 5No. of edges = 6degree = 1 ไม่มี

Graph H :No. of vertices = 5No. of edges = 6degree = 1 จุด e

Not isomorphic.

Page 30: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Determine whether the graphs are isomorphic.

Page 31: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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 จุด

Page 32: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 33: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Example

• Determine whether the graphs G and H are isomorphic.

Page 34: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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 จุด

Page 35: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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.

Page 36: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 37: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

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

Page 38: Graph - Prince of Songkla Universitystaff.cs.psu.ac.th/iew/cs344-381/Graph3.pdf · 2018-10-18 · •Adjacency matrices can also be used to represent undirected graphs with loops

Since Ag = Ah, it follows that f preserves edges. We conclude

that f is an isomorphism, so that G and H are isomorphic.


Recommended