CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.
-
Upload
justin-bennett -
Category
Documents
-
view
347 -
download
5
Transcript of CSE 211 Discrete Mathematics Chapter 8.3 Representing Graphs and Graph Isomorphism.
CSE 211Discrete Mathematics
Chapter 8.3Representing 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.
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
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
• 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
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
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
Adjacency Matrices• Example 5: Use an adjacency matrix to represent the
pseudograph shown in Figure 5.
0212
2110
1103
2030
FIGURE A Pseudograph.
8
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
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
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
Incidence Matrices• Example 7: Represent the pseudograph
shown in Figure 7 using an incidence matrix.
FIGURE 7 A Pseudograph.
12
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
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.
One to one and onto function
One to one and onto function
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
Isomorphism Example
• If isomorphic, label the 2nd graph to show the isomorphism, else identify difference.
a
b
cd
e
f
b
d
a
efc
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
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 …
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.
Example
a
e d
c
G H
b
a
e d
c
b
Are G and H isomorphic?
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
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?
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
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
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
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
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’
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’
Isomorphism of Graphs• Example 10: Determine whether the graphs
shown in below are isomorphic.•
FIGURE 10 The Graphs G and H. 31
Isomorphism of Graphs
FIGURE 11 The Subgraphs of G and H Made Up of Vertices of
Degree Three and the Edges Connecting Them.
32
Isomorphism of Graphs• Example 11: Determine whether the graphs
G and H displayed in below are isomorphic.
FIGURE 12 Graphs G and H. 33
CSE 211Discrete Mathematics
Chapter 8.4Connectivity
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.
Graph Theoretic Foundations
• Paths and Cycles:
• Walk in a graph G is v0, e1, v1, …, vl-1, el, vl
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
Paths, Cycles, and Trails
• A trail is a walk with no repeated edge.
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.
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.
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
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
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
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.
Example
Are the following graphs connected?
c
e
f
a
d
b
g
e
c
a
f
b
d
Yes No
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).
Example
• What are the connected components of the following graph?
b
a c
d e
h g
f
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}
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.
Example
• Find the cut vertices and cut edges in the following graph.
a
b c
d f
e h
g
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)
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
Graph Theoretic Foundations
• Trees and Forests:
• Tree – connected graph without any cycle
• Forest – a graph without any cycle
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.
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.
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.)
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.
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)}
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
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.
Distance in Trees and Graphs
• Find the diameter, eccentricity, radius and center of the given G.