Graphs Teacher
Graphs Teacher
Discrete Mathematics
Graphs
WUCT121 Graphs 1
Section 1. Graphs
1.1. Introduction
Graphs are used in many fields that require analysis of
routes between locations. These areas include
communications, computer networks and transportation.
WUCT121 Graphs 2
Example:
v2 e1 v1
e7
e8 e2 e4
e6
v5
e5
e3
v3 v4
e9
WUCT121 Graphs 3
1.2. Definitions:
1.2.1. Graph.
A graph G consists of a pair of non-empty finite sets V and
E. V is the set of vertices and E is the set of edges of G. The
elements of E are pairs of elements of V.
Example:
In the previous graph, e2 and e8 are parallel edges
1.2.3. Loops.
An edge which is defined by a single vertex is called a
loop. A vertex which is the endpoint of a loop is said to be
adjacent to itself.
v1
e1
WUCT121 Graphs 4
Exercises:
e1
e2
v1 v2
e3 e4
v3
v4 e5
V = {v1 , v 2 , v 3 , v 4 } .
Loop: e1 = ( v1 , v1 )
Parallel Edges: e3 and e4 .
v1 and v 2 are adjacent vertices.
e1 and e 2 are adjacent edges
WUCT121 Graphs 5
Write down the set V of vertices and the set E of edges
for the following graph, G1.
v3 v4
e5
e6 e4
e3
e1
v1 e2 v2
V = {v1 , v 2 , v 3 , v 4 },
E = {e1 , e2 , e3 , e4 , e5 , e6 }
= {( v1 , v1 ), ( v1 , v 4 ), ( v 2 , v 4 ), ( v 2 , v 4 ), ( v1 , v 2 ), ( v3 , v 4 )}
WUCT121 Graphs 6
Is the following graph G2 the same as the previous
graph G1?
e5
v4
e1 v1
e2 e3 e4
v3 v2
e6
Yes
Notes:
WUCT121 Graphs 7
Exercises:
v3
e1 e2
e5
v1 v2
e4
v6 e3
v5 e6 v4
WUCT121 Graphs 8
1.2.4. Degree.
The degree of a vertex v, written (v ) , is the number of
edges incident on v.
Notes:
Example:
e2
e1 v2
v1
e3
v3
( v1 ) = 4
WUCT121 Graphs 9
Exercises:
e5
e6 e4
e3
e1
v3 e2 v2
e1 e2 v2
v1 e3
e5 e4
v4
v3
v5 e6 v6
(v1 ) = 5, (v 2 ) = 3, (v3 ) = 2, (v 4 ) = 0,
(v5 ) = 1, (v6 ) = 1
WUCT121 Graphs 10
k
For each of the above graphs calculate (vi ) , where
i =1
k = 4 in the first graph and k = 6 in the second
k 4
The first graph, (vi ) = (vi ) = 12 .
i =1 i =1
k 6
The second graph, (vi ) = (vi ) = 12
i =1 i =1
Note:
WUCT121 Graphs 11
1.3. Eulers Laws
Proof:
Each edge of a graph, including loops by convention, has
two ends. Thus each edge contributes 2 to the sum of the
degrees of the vertices, by adding 1 to each of its endpoints.
Thus the sum of the degrees of the vertices equals twice the
number of edges.
G.
Exercises:
WUCT121 Graphs 12
1.3.2. Eulers Second Law
In any graph, the number of vertices which have odd
degree is even
Exercises:
v2
v1 e1
e2 e3
v3
v2
v1 e1
e2 e3
v3
WUCT121 Graphs 13
1.4. Simple Graphs and Sub-Graphs
Knowing the number of vertices in a graph and the degree
of each vertex is not enough information to draw the graph
in a unique way.
Example:
e1
v2
v1
e2
v4 v3
e3
Exercises:
WUCT121 Graphs 14
1.4.2. Sub-Graph
Let G = {VG , EG } be a graph.
H = {V H , E H } is said to be a sub-graph of G if
1. VH VG and
2. E H EG
1. VH VG and
2. E H EG and
3. H G
WUCT121 Graphs 15
Exercises:
Let G be given by
e5
v4
e1 v1
e2 e3 e4
v3 v2
e6
e5
v4
v1
e3
v3
e6
WUCT121 Graphs 16
1.5. Paths
Let G = {V , E} be a graph and let u, v V . A path from u
to v is an alternating sequence of vertices and edges of the
form: u , e 1 , v 1 , e 2 , v 2 ,K, e n , v .
Example:
e5
v4
e1 v1
e2 e3 e4
v3 v2
e6
But, after an extra long lunch, one might take the following
path v1 , e1 , v1 , e5 , v4 , e3 , v 2 , e4 , v 4 , e3 , v 2 , e6 , v3 .
WUCT121 Graphs 17
1.5.1. Length of a Path
Let G = {V , E} be a graph and let u, v V . A path of
length n from u to v is an alternating sequence of vertices
and edges of the form
u , e 1 , v 1 , e 2 , v 2 ,K, e n , v
Example:
Example:
WUCT121 Graphs 18
1.5.3. Closed Path
A path is closed if u = v . That is if the path begins and
finishes at the same vertex.
Example:
Examples:
WUCT121 Graphs 19
Exercises:
e5
v4
e1 v1
e2 e3 e4
v3 v2
e6
o v1 to v3
v1 , e2 , v 2 , e6 , v3
o v 4 to v1
v 4 , e5 , v1
o v 4 to v2
v 4 , e3 , v 2
WUCT121 Graphs 20
1.6. Connected Graphs
1.6.1. Definition
Let G = {V , E} be a graph. A pair of vertices u, v V are
said to be connected if there exists a path from u to v.
1. H is connected, and
Notes:
WUCT121 Graphs 21
Exercises:
e1 e2 v2
v1 e3
e5 e4
v4
v3
v5 e6 v6
H1 = {{v4 , v5 , v6 }, {e6 }}
No, there is no path from v4 to v5
H 2 = {{v4 }, { }}
Yes
H 3 = {{v1 , v2 , v3 }, {e3 , e5 }}
No, H 3 is a proper sub-graph of
H = {{v1 , v2 , v3 }, {e1 , e2 , e3 , e4 , e5 }} , which is a connected
sub-graph of G.
WUCT121 Graphs 22
Exercises:
v5 v4
e3
v5 v4
WUCT121 Graphs 23
For the following graph:
e2
v2
e1 v1
v7 e3 e4
v4 v6
e7
e5 e6 v3
v8
v5
WUCT121 Graphs 24
1.7. Isomorphic Graphs
Example:
No. The left-hand graph has 5 edges; the right hand graph
has 6 edges.
WUCT121 Graphs 25
v1 v'1
v5
v' 4 v' 3
v2
v4
v3 v' 2 v' 5
G G
WUCT121 Graphs 26
More formally:
f :V V g : E E
V V E E
v1 v1 e1 e1
v2 v 2 e2 e2
v3 v3 e3 e3
v4 v4 e4 e4
v5 v5 e5 e5
WUCT121 Graphs 27
1.7.1. Definition
Notes:
WUCT121 Graphs 28
- the same number of parallel edges.
Further,
WUCT121 Graphs 29
Exercises:
- 4 vertices
- 6 edges
- 1 connected component
- 1 loop
e3 e4 e5 e' 4 e' 5
e' 2
e'1
v4 e6 v3 v'1 e' 3 v' 3
G G
WUCT121 Graphs 30
Draw all possible graphs having 2 edges and 2 vertices;
that is, draw all non-isomorphic graphs having 2 edges and
2 vertices.
v1 v1 v1 v1
e1 e1
e1 e2 v2
v2 v2
e1
e2 e2
v2
e2
WUCT121 Graphs 31
1.8. Regular, Complete and Complete
Bipartite.
Exercises:
v3 v4
WUCT121 Graphs 32
Draw all 2-regular graphs with 2 vertices; 3 vertices; 4
vertices.
3 vertices 4 vertices
v1 v1 v 2
v3 v4
v 2 v3
Notes:
WUCT121 Graphs 33
Example:
Draw K 5
v1
v5
v2
v4 v3
Exercises:
K 3 : ( vi ) = 2
K 4 : ( vi ) = 3
v1
v1 v2
v 2 v3 v3 v4
WUCT121 Graphs 34
Complete the following sentences:
WUCT121 Graphs 35
1.8.3. Definition: Bipartite.
A simple graph G = {V , E} is said to be bipartite if there
exists sets U V and W V , such that;
1. U W = V and U W =
Notes:
WUCT121 Graphs 36
Example:
u1 u2
e2 e4
e1 e3
w1 w2 w3
Exercises:
o
u1 u2
e1 e2
w1 w2
U = {u1 , u 2 }; W = {w1 , w2 }
WUCT121 Graphs 37
o
u1 w2
w1 u2 U = {u1 , u2 }; W = {w1 , w2 }
w1 w2 w3 w4
w1 w2 w3
WUCT121 Graphs 38
1.8.4. Definition: Complete Bipartite.
A simple graph G = {V , E}, is said to be complete bipartite
if;
1. G is bipartite and
Notes:
n( E ) = n m
WUCT121 Graphs 39
Examples:
Draw K 2, 2 Draw K 2, 3
K 2, 2 K 2, 3
Exercises:
Draw K1, 3
K1, 3
Draw K 2, 4
K 2, 4
WUCT121 Graphs 40
Which of these graphs are bipartite.
No
u1
w1
w3
u3 u2
w2
Yes:
U = {u1 , u2 , u3 }
W = {w1 , w2 , w3 }
No
WUCT121 Graphs 41
1.9. Eulerian Graphs.
Problem 1:
If you are walking in the park, can you cross each bridge
exactly once?
Problem 2:
WUCT121 Graphs 42
Can you stroll around, crossing each bridge exactly once
and return to your starting point?
WUCT121 Graphs 43
Exercises:
o v 2 : v 2 , e3 , v3 , e4 , v 2
o v1 : v1 , e1 , v1
o v3 : v3 , e4 , v2 , e3 , v3
o v7 : None.
WUCT121 Graphs 44
1.9.3. Definition: Eulerian Circuit
Let G = {V , E} be a graph. A circuit in G is an Eulerian
circuit if every edge of G is included exactly once in the
circuit.
Exercises:
K3 K4
v1 v1 v2
v 2 v3 v3 v4
Yes No
v1
v5
v2
v4 v3 K 2, 3
No
K5 Yes
WUCT121 Graphs 45
Can you find an Eulerian path in the following graph
that is not an Eulerian circuit?
e1
v1 v2 e2
e6 e4 v3
v5 v4 e3
e5
v 4 , e3 , v3 , e2 , v 2 , e4 , v 4 , e5 , v5 , e6 , v1 , e1 , v 2
WUCT121 Graphs 46
For the Koenisberg Bridge Problem:
Discussion:
WUCT121 Graphs 47
In the Koenisberg Bridge setup, is it possible to cross each
bridge exactly once without necessarily finishing where
you start? That is, is there an Eulerian path in K?
Example:
( A) = 3 ; ( B ) = 5 ; (C ) = 3 ; ( D) = 3
WUCT121 Graphs 48
1.10. Trees and Spanning Trees.
Notes:
Exercise:
G1 , G4 , G6
WUCT121 Graphs 49
Trees can be used in conjunction with connected graphs.
Notes.
Exercises:
WUCT121 Graphs 50
If not, do two spanning trees for the same graph have
anything in common?
WUCT121 Graphs 51
Example:
B C
G: E
A D
B C B C B C
E E E
A D A D A D
T1 T2 T3
Note:
Any two spanning trees will have the same number of
edges.
WUCT121 Graphs 52
To make the problem more practical:
B 3 C
5
G: 3.5 1 E
A 3 D
T1 = 3 + 5 + 3.5 + 1 = 12.5
T2 = 3 + 5 + 3.5 + 3 = 14.5
T3 = 3 + 1 + 3 + 5 = 12
WUCT121 Graphs 53
When the graph has a large number of vertices, it is not
easy to find all spanning trees. In fact, we are not usually
interested in finding all spanning trees for a graph. We
would like an algorithm which finds the minimum spanning
tree for a weighted connected graph. Kruskal's Algorithm is
one such algorithm.
WUCT121 Graphs 54
1.10.4. Kruskal's Algorithm
Example.
WUCT121 Graphs 55
Kruskal's Algorithm then includes the 3 additional columns
as follows:
WUCT121 Graphs 56
Kruskal's algorithm will always produce a minimum
spanning tree for any connected weighted graph G.
WUCT121 Graphs 57
Kruskal's Algorithm for finding minimum spanning trees
for weighted graphs (Epp's version) is then:
3. While ( m < n 1)
b. Delete e from E.
WUCT121 Graphs 58
1.10.5. Theorem: Kruskals Output.
When a connected weighted graph is input into Kruskal's
algorithm, the output is a minimum spanning tree.
Exercises:
12
v1 v2
4 7 20
5
10
v3 v5 v6
2
v4
18
8 15 19
v7 v8
13
WUCT121 Graphs 59
Cumulative
Will adding edge
Weight Action taken weight of
Edge make circuit?
sub-graph
( v4 , v5 ) 2 No Added 2
( v1 , v3 ) 4 No Added 6
( v2 , v5 ) 5 No Added 11
( v3 , v7 ) 8 No Added 19
( v3 , v4 ) 10 No Added 29
( v7 , v8 ) 13 No Added 42
( v6 , v8 ) 19 No Added 61
WUCT121 Graphs 60
The minimum spanning tree is:
v1 v2
v3 v5 v6
v4
v7 v8
WUCT121 Graphs 61
1.11. Planar Graphs.
Given a graph which is drawn with incidental crossings of
edges, is it possible to determine whether an isomorphic
graph could be drawn without any crossings of the edges?
Exercises:
v1
K4 :
v1 v2
v4
v3 v4 v3 v2
Yes
K 3, 3
No
WUCT121 Graphs 62
1.11.1. Definition: Plane Graph.
A graph G is said to be a plane graph if it is drawn in the
plane in such a way that there are no incidental crossings of
edges.
Notes:
Exercises:
1
3
2
1
4 3
2
WUCT121 Graphs 63
1.11.2. Definition: Planar Graph.
A graph G is said to be a planar graph if it can be drawn in
the plane without incidental crossings of edges.
Notes:
Exercises:
1
3
2 v = 4, e = 5, f = 3
v e+ f = 45+3= 2
WUCT121 Graphs 64
1
4 3
2
v = 5, e = 7, f = 4
v e+ f = 57+4 = 2
1 2 4
3 v = 4, e = 6, f = 4
ve+ f = 46+4 = 2
WUCT121 Graphs 65
The following theorem includes a condition which can be
checked in the original graph.
1. e 3v 6 , AND
WUCT121 Graphs 66
Exercises:
1. Check e 3v 6
e = 14, v = 8
3v 6 = 18
e < 3v 6
WUCT121 Graphs 67
Decide whether these graphs are planar.
K 3, 3
1. Check e 3v 6
e = 9, v = 6
3v 6 = 12
e < 3v 6
WUCT121 Graphs 68
o
v1 v2
v3 v4
v5 v6 v7
1. Check e 3v 6
e = 11, v = 7
3v 6 = 15
e < 3v 6
v3
v5 v6 v7
v 4
v2
WUCT121 Graphs 69
o
v1
v5
v2
v4 v3
1. Check e 3v 6
e = 10, v = 5
3v 6 = 9
e > 3v 6
Thus K 5 is not planar
WUCT121 Graphs 70
1.11.5. Theorem: Smallest Non-Planar Graphs
K 3, 3 and K 5 are the smallest possible non-planar graphs.
or K 5 as a sub-graph.
Example:
v5
v2 v3
v8
v6
v1 v4
v7
WUCT121 Graphs 71
Redrawing the graph without crossings:
v 2 v3
v5
v7
v1 v 4
v6 v8
v = 8, e = 11, f = 5
v e + f = 8 11 + 5 = 2
WUCT121 Graphs 72