CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

61
CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism

Transcript of CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Page 1: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

CSE 211Discrete Mathematics

Chapter 8.3Representing Graphs and

Graph Isomorphism

Page 2: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

§8.3: Graph Representations & Isomorphism

• Graph representations:– Adjacency lists.– Adjacency matrices.– Incidence matrices.

• Graph isomorphism:– Two graphs are isomorphic iff they are identical

except for their node names.

Page 3: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Adjacency Lists

• A table with 1 row per vertex, listing its adjacent vertices.

a b

dc

f

e

Vertex

Adjacent Vertices

a b

b, c a, c, e, f

c a, b, f d e b f c, b

Page 4: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Directed Adjacency Lists

• 1 row per node, listing the terminal nodes of each edge incident from that node.

0 1

23

4

node Terminal nodes

0 3

1 0, 2, 4

2 1

3

4 0,2

Page 5: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

• A simple graph G = (V,E) with n vertices can be represented by its adjacency matrix, A, where the entry aij in row i and column j is:

Adjacency Matrix

otherwise

in edgean is }{ if

0

1 G,vva ji

ij

Page 6: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Adjacency Matrix Example

a b c d e f

abcdef

From

To

W5

db

a

c

e

f

{v1,v2}

row column

0 1 0 0 1 11 0 1 0 0 10 1 0 1 0 10 0 1 0 1 11 0 0 1 0 11 1 1 1 1 0

Page 7: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Adjacency Matrices

• Matrix A=[aij], where aij is 1 if {vi, vj} is an edge of G, 0 otherwise.

ab

c

d

0001

0011

0101

1110a

b

c

d

a b c d

Page 8: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Adjacency Matrices• Example 5: Use an adjacency matrix to represent the

pseudograph shown in Figure 5.

0212

2110

1103

2030

FIGURE A Pseudograph.

8

Page 9: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Incidence Matrix

• Let G = (V,E) be an undirected graph. Suppose v1,v2,v3,…,vn are the vertices and e1,e2,e3,…,em are the edges of G. The incidence matrix w.r.t. this ordering of V and E is the nm matrix M = [mij], where

otherwise

with incident is edge if

0

1 ijij

vem

Page 10: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Incidence Matrix Example

• Represent the graph shown with an incidence matrix.

1 1 0 0 0 00 0 1 1 0 10 0 0 0 1 11 0 1 0 0 00 1 0 1 1 0

v1

v2

v3

v4

v5

vertices

e1 e2 e3 e4 e5 e6 edgesv1 v2 v3

v4 v5

e1e2

e3 e4 e5

e6

Page 11: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Incidence matrices

• Matrix M=[mij], where mij is 1 when edge ej

is incident with vi, 0 otherwise

v1

v2

v3

v4

e1 e2 e3 e4v1

v4

v3

v2

e5

11010

000

000

001

11

11

11e1

e2

e5

e4

e3

Page 12: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Incidence Matrices• Example 7: Represent the pseudograph

shown in Figure 7 using an incidence matrix.

FIGURE 7 A Pseudograph.

12

Page 13: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Isomorphism

• Two simple graphs are isomorphic if:

– there is a one-to one correspondence between the vertices of the two graphs

– the adjacency relationship is preserved

Page 14: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Isomorphism (Cont.)

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

Page 15: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

One to one and onto function

Page 16: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

One to one and onto function

Page 17: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

u1

u3 u4

u2v1

v3 v4

v2

G H

Are G and H isomorphic?

f(u1) = v1, f(u2) = v4, f(u3) = v3, f(u4) = v2

Page 18: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Isomorphism Example

• If isomorphic, label the 2nd graph to show the isomorphism, else identify difference.

a

b

cd

e

f

b

d

a

efc

Page 19: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Are These Isomorphic?

• If isomorphic, label the 2nd graph to show the isomorphism, else identify difference.

ab

c

d

e

* Same # ofvertices

* Same # ofedges

* Different# of vertices of

degree 2! (1 vs 3)

Example 11: a more general solution

Page 20: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Invariants

• Invariants – properties that two simple graphs must have in common to be isomorphic– Same number of vertices

– Same number of edges

– Degrees of corresponding vertices are the same

– If one is bipartite, the other must be; if one is complete, the other must be; and others …

Page 21: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Graph isomorphism Example

Graph GGraph H An isomorphism

between G and H

ƒ(a) = 1ƒ(b) = 6ƒ(c) = 8ƒ(d) = 3ƒ(g) = 5ƒ(h) = 2ƒ(i) = 4ƒ(j) = 7

The two graphs shown below are isomorphic, despite their different looking drawings.

Page 22: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

a

e d

c

G H

b

a

e d

c

b

Are G and H isomorphic?

Page 23: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• Are these two graphs isomorphic?

– They both have 5 vertices– They both have 8 edges– They have the same number of vertices with

the same degrees: 2, 3, 3, 4, 4.

G H

u1 u2

u5 u3

u4

v1 v2

v5

v3

v4

Page 24: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example (Cont.)

u1 u2 u3 u4 u5

u1 0 1 0 1 1u2 1 0 1 1 1u3 0 1 0 1 0u4 1 1 1 0 1u5 1 1 0 1 0

v1 v2 v3 v4 v5

v1 0 0 1 1 1v2 0 0 1 0 1v3 1 1 0 1 1v4 1 0 1 0 1v5 1 1 1 1 0

– G and H don’t appear to be isomorphic.

– However, we haven’t tried mapping vertices from G onto H yet.

v1 v3 v2 v5 v4

v1

v3

v2

v5

v4

G H H G?

Page 25: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example (Cont.)

• Start with the vertices of degree 2 since each graph only has one:

deg(u3) = deg(v2) = 2 therefore f(u3) = v2

G H

u1 u2

u5 u3

u4

v1 v2

v5

v3

v4

Page 26: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example (Cont.)• Now consider vertices of degree 3

deg(u1) = deg(u5) = deg(v1) = deg(v4) = 3

therefore we must have either one of

f(u1) = v1 and f(u5) = v4

f(u1) = v4 and f(u5) = v1

G H

u1 u2

u5 u3

u4

v1 v2

v5

v3

v4

Page 27: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example (Cont.)

• Now try vertices of degree 4:deg(u2) = deg(u4) = deg(v3) = deg(v5) = 4

therefore we must have one of:f(u2) = v3 and f(u4) = v5 or

f(u2) = v5 and f(u4) = v3

G H

u1 u2

u5 u3

u4

v1 v2

v5

v3

v4

Page 28: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example (Cont.)

• There are four possibilities (this can get messy!)f(u1) = v1, f(u2) = v3, f(u3) = v2, f(u4) = v5, f(u5) = v4

f(u1) = v4, f(u2) = v3, f(u3) = v2, f(u4) = v5, f(u5) = v1

f(u1) = v1, f(u2) = v5, f(u3) = v2, f(u4) = v3, f(u5) = v4

f(u1) = v4, f(u2) = v5, f(u3) = v2, f(u4) = v3, f(u5) = v1

G H

u1 u2

u5 u3

u4

v1 v2

v5

v3

v4

Page 29: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example (Cont.)

u1 u2 u3 u4 u5

u1 0 1 0 1 1u2 1 0 1 1 1u3 0 1 0 1 0u4 1 1 1 0 1u5 1 1 0 1 0

v1 v2 v3 v4 v5

v1 0 0 1 1 1v2 0 0 1 0 1v3 1 1 0 1 1v4 1 0 1 0 1v5 1 1 1 1 0

We permute the adjacency matrix of H (per function choices above) to see if we get the adjacency of G. Let’s try:

f(u1) = v1, f(u2) = v3, f(u3) = v2, f(u4) = v5, f(u5) = v4

Does G = H’? Yes!

v1 v3 v2 v5 v4

v1 0 1 0 1 1v3 1 0 1 1 1v2 0 1 0 1 0v5 1 1 1 0 1v4 1 1 0 1 0

G H H’

Page 30: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example (Cont.)

u1 u2 u3 u4 u5

u1 0 1 0 1 1u2 1 0 1 1 1u3 0 1 0 1 0u4 1 1 1 0 1u5 1 1 0 1 0

v1 v2 v3 v4 v5

v1 0 0 1 1 1v2 0 0 1 0 1v3 1 1 0 1 1v4 1 0 1 0 1v5 1 1 1 1 0

It turns out that

f(u1) = v4, f(u2) = v3, f(u3) = v2, f(u4) = v5, f(u5) = v1

also works.

v4 v3 v2 v5 v1

v4 0 1 0 1 1v3 1 0 1 1 1v2 0 1 0 1 0v5 1 1 1 0 1v1 1 1 0 1 0

G H H’

Page 31: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Isomorphism of Graphs• Example 10: Determine whether the graphs

shown in below are isomorphic.•

FIGURE 10 The Graphs G and H. 31

Page 32: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Isomorphism of Graphs

FIGURE 11 The Subgraphs of G and H Made Up of Vertices of

Degree Three and the Edges Connecting Them.

32

Page 33: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Isomorphism of Graphs• Example 11: Determine whether the graphs

G and H displayed in below are isomorphic.

FIGURE 12 Graphs G and H. 33

Page 34: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

CSE 211Discrete Mathematics

Chapter 8.4Connectivity

Page 35: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Paths in Undirected Graphs

• There is a path from vertex v0 to vertex vn if there is a sequence of edges from v0 to vn

– This path is labeled as v0,v1,v2,…,vn and has a length of n.

• The path is a circuit if the path begins and ends with the same vertex.

• A path is simple if it does not contain the same edge more than once.

Page 36: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Graph Theoretic Foundations

• Paths and Cycles:

• Walk in a graph G is v0, e1, v1, …, vl-1, el, vl

Page 37: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Graph Theoretic Foundations

• Paths and Cycles:

• IF v0, v1, …, vl are distinct (except possible v0,vl) then the walk is a path.

• Denoted by v0, v1, …, vl or e1, e2, …, el

• Length of path is l

Page 38: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Paths, Cycles, and Trails

• A trail is a walk with no repeated edge.

Page 39: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Graph Theoretic Foundations

• Paths and Cycles:

• A path or walk is closed if v0 = vl

• A closed path containing at least one edge is called a cycle.

Page 40: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Paths in Undirected Graphs

• A path or circuit is said to pass through the vertices v0, v1, v2, …, vn or traverse the

edges e1, e2, …, en.

Page 41: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• u1, u4, u2, u3

– Is it simple? – yes

– What is the length? – 3

– Does it have any circuits? – no

u1 u2

u5 u4 u3

Page 42: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• u1, u5, u4, u1, u2, u3

– Is it simple?– yes

– What is the length?– 5

– Does it have any circuits?– Yes; u1, u5, u4, u1

u1 u2

u5 u3

u4

Page 43: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• u1, u2, u5, u4, u3

– Is it simple?– yes

– What is the length?– 4

– Does it have any circuits?– no

u1 u2

u5 u3

u4

Page 44: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Connectedness

• An undirected graph is called connected if there is a path between every pair of distinct vertices of the graph.

• There is a simple path between every pair of distinct vertices of a connected undirected graph.

Page 45: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

Are the following graphs connected?

c

e

f

a

d

b

g

e

c

a

f

b

d

Yes No

Page 46: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Connectedness (Cont.)

• A graph that is not connected is the union of two or more disjoint connected subgraphs (called the connected components of the graph).

Page 47: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• What are the connected components of the following graph?

b

a c

d e

h g

f

Page 48: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• What are the connected components of the following graph?

b

a c

d e

h g

f

{a, b, c}, {d, e}, {f, g, h}

Page 49: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Cut edges and vertices

• If one can remove a vertex (and all incident edges) and produce a graph with more connected components, the vertex is called a cut vertex.

• If removal of an edge creates more connected components the edge is called a cut edge or bridge.

Page 50: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• Find the cut vertices and cut edges in the following graph.

a

b c

d f

e h

g

Page 51: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• Find the cut vertices and cut edges in the following graph.

a

b c

d f

e h

g

Cut vertices: c and eCut edge: (c, e)

Page 52: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Graph Theoretic Foundations• Connectivity:

• Connectivity (G) of graph G is …

• G is k connected if (G) k

• Separator or vertex-cut Cut vertex

Separation pair

Page 53: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Graph Theoretic Foundations

• Trees and Forests:

• Tree – connected graph without any cycle

• Forest – a graph without any cycle

Page 54: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Connectedness in Directed Graphs

• A directed graph is strongly connected if there is a directed path between every pair of vertices.

• A directed graph is weakly connected if there is a path between every pair of vertices in the underlying undirected graph.

Page 55: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• Is the following graph strongly connected? Is it weakly connected?

a b

c

e d

This graph is strongly connected. Why? Because there is a directed path between every pair of vertices.

If a directed graph is strongly connected, then it must also be weakly connected.

Page 56: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• Is the following graph strongly connected? Is it weakly connected?

a b

c

e d

This graph is not strongly connected. Why not? Because there is no directed path between a and b, a and e, etc.

However, it is weakly connected. (Imagine this graph as an undirected graph.)

Page 57: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Connectedness in Directed Graphs

• The subgraphs of a directed graph G that are strongly connected but not contained in larger strongly connected subgraphs (the maximal strongly connected subgraphs) are called the strongly connected components or strong components of G.

Page 58: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Example

• What are the strongly connected components of the following graph?a b

c

e d

This graph has three strongly connected components:• The vertex a• The vertex e• The graph consisting of V = {b, c, d} and E = { (b, c), (c, d), (d, b)}

Page 59: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Consider a connected graph G. The distance between vertices u and v in G, written d(u, v), is the length of the shortest path between u and v. The distance of G, written diam(G), is the maximum distance between any two points in G. For example, in Fig. 1-8(a), d(A,F) = 2 and diam(G) = 3, whereas in Fig. 1-8(b), d(A, F) = 3 and diam(G) = 4

Distance in Trees and Graphs

Page 60: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Distance in Trees and Graphs• If G has a u, v-path, then the distance from

u to v, written dG(u, v) or simply d(u, v), is the least length of u, v-path.

• The diameter (diam G) is maxu,vV(G)d(u,v)

• The eccentricity [(u)] of a vertex u is maxvV(G)d(u,v)

• The radius of G (rad G) is minuV(G)(u)

• A vertex with minimum eccentricity in G is called a center of G.

Page 61: CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.

Distance in Trees and Graphs

• Find the diameter, eccentricity, radius and center of the given G.