0% found this document useful (0 votes)
88 views39 pages

7 Graphs

The two graphs are isomorphic. There exists a bijection between the vertices of the graphs that preserves adjacency. Specifically, the function f(u1) = v1, f(u2) = v2, f(u3) = v3, f(u4) = v4, f(u5) = v5 is an isomorphism between the graphs, since it maps adjacent vertices in the first graph to adjacent vertices in the second graph.

Uploaded by

Somaiah Sulaiman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views39 pages

7 Graphs

The two graphs are isomorphic. There exists a bijection between the vertices of the graphs that preserves adjacency. Specifically, the function f(u1) = v1, f(u2) = v2, f(u3) = v3, f(u4) = v4, f(u5) = v5 is an isomorphism between the graphs, since it maps adjacent vertices in the first graph to adjacent vertices in the second graph.

Uploaded by

Somaiah Sulaiman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 39

Graphs (L7)

1
Introduction to Graphs
Definition: A simple graph G = (V, E) consists of V,
a nonempty set of vertices, and E, a set of
unordered pairs of distinct elements of V called
edges.
For each eE, e = {u, v} where u, v  V.
An undirected graph (not simple) may contain loops.
An edge e is a loop if e = {u, u} for some uV.

2
Introduction to Graphs
Definition: A directed graph G = (V, E) consists of
a set V of vertices and a set E of edges that are
ordered pairs of elements in V.
For each eE, e = (u, v) where u, v  V.
An edge e is a loop if e = (u, u) for some uV.
A simple graph is just like a directed graph, but
with no specified direction of its edges.

3
Graph Models
Example I: How can we represent a network of
(bi-directional) railways connecting a set of cities?
We should use a simple graph with an edge {a, b}
indicating a direct train connection between cities
a and b.

Toronto Boston
Lübeck

New York
Hamburg
Washington
4
Graph Models
Example II: In a round-robin tournament, each
team plays against each other team exactly once.
How can we represent the results of the
tournament (which team beats which other team)?
We should use a directed graph with an edge (a, b)
indicating that team a beats team b.

Maple Leafs Bruins

Penguins Lübeck Giants


5
Graph Terminology

Definition: Two vertices u and v in an undirected


graph G are called adjacent (or neighbors) in G if
{u, v} is an edge in G.
If e = {u, v}, the edge e is called incident with the
vertices u and v. The edge e is also said to connect
u and v.
The vertices u and v are called endpoints of the
edge {u, v}.

6
Graph Terminology

Definition: The degree of a vertex in an


undirected graph is the number of edges incident
with it, except that a loop at a vertex contributes
twice to the degree of that vertex.
In other words, you can determine the degree of a
vertex in a displayed graph by counting the lines
that touch it.
The degree of the vertex v is denoted by deg(v).

7
Graph Terminology
Let us look at the same graph again and determine
the number of its edges and the sum of the
degrees of all its vertices:
i h
d
a e
g
b c f j

Result: There are 9 edges, and the sum of all


degrees is 18. This is easy to explain: Each new
edge increases the sum of degrees by exactly two.
8
Graph Terminology
The Handshaking Theorem: Let G = (V, E) be an
undirected graph with e edges. Then
2e = vV deg(v)

Example: How many edges are there in a graph


with 10 vertices, each of degree 6?
Solution: The sum of the degrees of the vertices is
610 = 60. According to the Handshaking Theorem,
it follows that 2e = 60, so there are 30 edges.

9
Special Graphs
Definition: The complete graph on n vertices,
denoted by Kn, is the simple graph that contains
exactly one edge between each pair of distinct
vertices.

K1 K2 K3 K4 K5

10
Special Graphs
Definition: A simple graph is called bipartite if its
vertex set V can be partitioned into two disjoint
nonempty sets V1 and V2 such that every edge in
the graph connects a vertex in V1 with a vertex in
V2 (so that no edge in G connects either two
vertices in V1 or two vertices in V2).
For example, consider a graph that represents
each person in a village by a vertex and each
marriage by an edge.
This graph is bipartite, because each edge
connects a vertex in the subset of males with a
vertex in the subset of females (if we think of
traditional marriages).
11
Special Graphs
Example I: Is C3 bipartite?

v1 No, because there is no way to


partition the vertices into two sets
v2 v3 so that there are no edges with
both endpoints in the same set.
Example II: Is C6 bipartite?
v1 v6 v1 v6
Yes, because
v2 v5 we can display v5 v2
C6 like this: v4
v3 v4 v3
12
Special Graphs
Definition: The complete bipartite graph Km,n is
the graph that has its vertex set partitioned into
two subsets of m and n vertices, respectively. Two
vertices are connected if and only if they are in
different subsets.

K3,2 K3,4

13
Exercises

14
Representing Graphs
Graphs can be represented by
•Adjacency Matrix (Explained in Relations chapter)
•Incidence Matrix
a
Example: What is the adjacency
b
matrix AG for the following
d
graph G based on the order of
vertices a, b, c, d ? c
0 1 1 1
1 0 0 1
Solution: AG  
1 0 0 1
 
1 1 1 0

Note: Adjacency matrices of undirected graphs


are always symmetric.
15
Representing Graphs
Definition: Let G = (V, E) be an undirected graph with |V| = n.
Suppose that the vertices and edges of G are listed in
arbitrary order as v1, v2, …, vn and e1, e2, …, em, respectively.
The incidence matrix of G with respect to this listing of the
vertices and edges is the nm zero-one matrix with 1 as its
(i, j) entry when edge ej is incident with vi, and 0 otherwise.
In other words, for an incidence matrix M = [mij],
mij = 1 if edge ej is incident with vi
mij = 0 otherwise.

16
Representing Graphs
Example: What is the incidence
a 1
matrix M for the following
2 b
graph G based on the order of
vertices a, b, c, d and edges 1, 2, d 3 5
3, 4, 5, 6? 4 c
6
Solution:

Note: Incidence matrices of directed graphs


contain two 1s per column for edges connecting two
vertices and one 1 per column for loops.
17
Isomorphism of Graphs
Definition: The simple graphs G1 = (V1, E1) and G2 =
(V2, E2) are isomorphic if there is a bijection (an
one-to-one and onto function) f from 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.
In other words, G1 and G2 are isomorphic if their
vertices can be ordered in such a way that the
adjacency matrices MG1 and MG2 are identical.
18
Isomorphism of Graphs
From a visual standpoint, G1 and G2 are isomorphic
if they can be arranged in such a way that their
displays are identical (of course without changing
adjacency).
Unfortunately, for two simple graphs, each with n
vertices, there are n! possible isomorphisms that
we have to check in order to show that these
graphs are isomorphic.
However, showing that two graphs are not
isomorphic can be easy.

19
Isomorphism of Graphs
For this purpose we can check invariants, that is,
properties that two isomorphic simple graphs must
both have.
For example, they must have
• the same number of vertices,
• the same number of edges, and
• the same degrees of vertices.
Note that two graphs that differ in any of these
invariants are not isomorphic, but two graphs that
match in all of them are not necessarily isomorphic.
20
Isomorphism of Graphs
Example I: Are the following two graphs isomorphic?
a a
b e e
b
c d c d
Solution: Yes, they are isomorphic, because they
can be arranged to look identical. You can see this
if in the right graph you move vertex b to the left
of the edge {a, c}. Then the isomorphism f from
the left to the right graph is: f(a) = e, f(b) = a,
f(c) = b, f(d) = c, f(e) = d.
21
Isomorphism of Graphs
Example II: How about these two graphs?
a a
b
e e
b
c c
d d
Solution: No, they are not isomorphic, because
they differ in the degrees of their vertices.
Vertex d in right graph is of degree one, but there
is no such vertex in the left graph.
22
Example
Are these two graphs isomorphic?
u1 u2 v1 v2
v5
v3
u5 u3
G u4 H v4
– 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.
Exercises
Exercises (Find Isomorphism)
Euler Paths and Circuits
The Seven bridges of Königsberg

C
c

D
A
a d

B
b
Euler Paths and Circuits

An Euler path is a path using every edge of


the graph G exactly once.
An Euler circuit is an Euler path that
returns to its start.
C

Does this graph have an


A D
Euler circuit?
No. B
Necessary and Sufficient Conditions
How about multigraphs?
A connected multigraph has a Euler circuit
iff each of its vertices has an even degree.
A connected multigraph has a Euler path but
not an Euler circuit iff it has exactly two
vertices of odd degree.
Example
Which of the following graphs has an Euler
circuit?
a b a b a b

e e

d c d c c d e

yes no no
(a, e, c, d, e, b, a)
Example
Which of the following graphs has an Euler
path?
a b a b a b

e e

d c d c c d e

yes no yes
(a, e, c, d, e, b, a ) (a, c, d, e, b, d, a, b)
Euler Circuit in Directed Graphs

NO (a, g, c, b, g, e, d, f, a) NO
Euler Path in Directed Graphs

NO (a, g, c, b, g, e, d, f, a) (c, a, b, c, d, b)
Exercise
Exercise
Shortest Path
Graphs that have a number assigned to
each edge are called weighted graphs.

MILES BOS
2534 860

191
1855 722 NY
CHI
SF DEN 908
957
606

760
4
349 83

900
2451

109
10
ATL
LA 595
MIA
Weighted Graphs
FARES

BOS
$129 $79
$39
$99 $59 NY
CHI
SF DEN $69
$89

$79

$99
$39 $89 $12 9
ATL
LA

$69
MIA
Weighted Graphs

A weighted graph is a graph in which each edge


(u, v) has a weight w(u, v). Each weight is a
real number.
Weights can represent distance, cost, time,
capacity, etc.
The length of a path in a weighted graph is the
sum of the weights on the edges.
Dijkstra’s Algorithm finds the shortest path
between two vertices.
Exercise

You might also like