7 Graphs
7 Graphs
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 eE, 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 uV.
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 eE, e = (u, v) where u, v V.
An edge e is a loop if e = (u, u) for some uV.
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.
6
Graph Terminology
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
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?
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
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:
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
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