Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture 19-20

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

Graphs, Graph

Isomorphism
Muhammad Umar Nasir
Lecturer FCS, Riphah International University Lahore
Graph:

 A graph G consists of two things


 A set V of elements called vertices
 A set E of edges such that each e in E is identified with unique pair
(u,v) of vertices in V, denoted by e=(u,v)
 Each has either one or two vertices associated with it, called its
endpoints. An edge is said to connect its endpoints.
Graph:

 Infinite Graph:
 The set of vertices V of a graph G may be infinite. A graph with an
infinite vertex set is called infinite graph.

 Finite Graph:
 A graph with a finite number of vertices associated with it, called its
endpoints. An edge is said to connect its endpoints.
Graph:

 Simple Graph:
 A graph in which each edge connects two different vertices and
where no two edges connect the same pair of vertices is called simple
graph.

 Multi Graph:
 Graphs that may have multiple edges connecting the same vertices
are called multigraphs. When there are m different edges associated
to the same unordered pair of vertices {u, v}, we also say that {u, v}
is an edge of multiplicity m.
Graph:

 Pseudo Graph:
 Graphs that may include loops, and possibly multiple edges
connecting the same pair of vertices, are sometimes called pseudo
graph. (An edge that connects a vertex to itself is called loop edge.)

 Undirected Graph:
 A graph having undirected edges, is called undirected graph.
Graph:

 Directed Graph:
 Directed graph has directed edges. It is also called digraph. It has two types
 Simple Directed graph:
 When a directed graph has no loops and has no multiple directed edges is
called simple directed graph.
 Multi Directed graph:
 Directed graphs that have multiple directed edges from one vertex to
another, such graphs are called multi directed graph.

 Mixed Graph:
 A graph with both directed and undirected edges is called a mixed graph
Graph:
Graph:

 Adjacents:
 In undirected graphs two vertices are said to be adjacent if there is an
edge between them.
 When (u, v) is an edge of the graph G with directed edges, u is said to
be adjacent to v and v is said to be adjacent from u.
 The vertex u is called the initial vertex of (u, v), and v is called the
terminal or end vertex of (u, v).
Graph:

a is adjacent to b , f
b is adjacent to a , f , e , c
c is adjacent to b , f , e , d
d is adjacent to c
e is adjacent to b , c , f
f is adjacent to a , b , c , e
g is adjacent to none
Graph:

a is adjacent to a , b , e
b is adjacent to d
c is adjacent to c , b
d is adjacent to c , e
e is adjacent to a , d , e
f is adjacent to none
Graph:

 Degree of a vertex:
 In an undirected graph, number of edges on a vertex is called degree
of the vertex. The degree of the vertex v is denoted by deg(v).
 In a directed graph the number of edges coming out of a vertex is
called out-degree and number of edges coming into it is called in-
degree of the vertex.
 In a directed graph the in-degree of a vertex v, denoted by deg – (v).
The out-degree of v, is denoted by deg + (v).
Graph:

 Degree of a vertex:
 For Directed Graph:
 Sum of all in-degrees = sum of all out-degrees = number of edges.

 For Undirected Graph:


 Sum of all degrees = 2E
Graph:

 In Undirected Graphs:
 In G, deg(a) = 2, deg(b) = 4, deg(c) = 4, deg(d) = 1, deg(e) = 3,
deg(f) = 4, and deg(g) = 0.
 2+4+4+1+3+4+0 = 2(9)
 18=18
 In H, deg(a) = 4, deg(b) = 6, deg(c) = 1, deg(d) = 5, and deg(e) = 6.
 4+6+1+5+6=2(11)
 22=22
Graph:

 In directed Graph:
 The in-degrees in G are
 deg – (a) = 2, deg – (b) = 2, deg – (c) = 3, deg – (d) = 2, deg – (e) = 3,
and deg – (f) = 0.
 The out-degrees in G are
 deg +(a) = 4, deg +
(b) = 1, deg +
(c) = 2, deg +
(d) = 2, deg +
(e) = 3,
and deg + (f) =0.
 Sum of In-degree=Sum of Out-degree=No of edges
 2+2+3+2+3+0 = 4+1+2+2+3+0 = 12
 12 = 12 = 12
Graph:

 Isolated and Pendant Vertices:


 A vertex of degree zero is called isolated. It follows that an isolated
vertex is not adjacent to any vertex. A vertex is pendant if and only if
it has degree one. Consequently, a pendant vertex is adjacent to
exactly one other vertex.
Graphs Representation:

A graph can be represented in memory using two methods.


 Adjacency list
 Adjacency Matrix
Graphs Representation:

1) Adjacency List
Adjacency list specifies the vertices that are adjacent to each vertex of the graph.

Vertex Adjacent Vertices

a b,c,e

b a

c a,d,e

d c,e

e a,c,d
Graphs Representation:

Vertex Adjacent Vertices

a b , c , d, e

b b,d

c a,c,e

e b,c,d
Graphs Representation:

2) Adjacency Matrix
 Suppose that G = (V, E) is a simple graph where |V| = n. The
adjacency matrix is the n ˟ n zero-one matrix with 1 as its (i, j)th
entry when Vi and lJ 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=
Graphs Representation:

a b c d

a 0 1 1 1

b 1 0 1 0

c 1 1 0 0

d 1 0 0 0
Graphs Representation:

Adjacency Matrix for a Pseudo graph

a b c d

a 0 3 0 2

b 3 0 1 1

c 0 1 1 2

d 2 1 2 0
Graph Isomorphism:

 The word isomorphism comes from the Greek roots isos for
"equal" and morphe for "form."
 The simple graphs G1 = (V1, E1) and G2 = (V2, E2) are
isomorphic if there is a one-to-one and onto function f from VI
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.
Graph Isomorphism:

Example 1:
Show that the graphs G = (V, E) and H = (W, F), in following Figures, are isomorphic.
Graph Isomorphism:

 Solution: The function f with f(U1) = VI, 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 UI and U2, UI and U3, U2 and U4, and U3 and U4,
and each of the pairs f(U1) = V1 and f(U2) = V4, f(U1) = VI and f(U3)
= V3, f(U2) = V4 and f(U4) = V2,and f(U3) = V3 and f(U4) = V2 are
adjacent in H.
Graph Isomorphism:
Example 2:
Show that graphs displayed in following Figures are not isomorphic.
Graph Isomorphism:

 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.
Graph Isomorphism:
Example 3:
Determine whether the graphs shown in following Figures are isomorphic or not.
Graph Isomorphism:

 Solution:
 The graphs G and H both have eight vertices and 10 edges. They also
both have four vertices of degree two and four of degree three.
 However, G and H are not isomorphic. To see this, note that because
deg(a) = 2 in G, a must correspond to either t, u, x, or y in H, because
these are the vertices of degree two in H. However, each of these
four vertices in H is adjacent to another vertex of degree two in H,
which is not true for a in G.

You might also like