V - UOW

WUCT121
Discrete Mathematics
Graphs
WUCT121
Graphs
1
Section 1.
1.1.
Graphs
Introduction
Graphs are used in many fields that require analysis of
routes between locations. These areas include
communications, computer networks and transportation.
Diagrammatically a graph is drawn as points representing
locations and lines or curves which represent connections
between locations. The points are known as vertices and the
lines are called edges.
WUCT121
Graphs
2
Example:
v2
e1
v1
e7
e2
e8
e6
e4
e5
e3
v3
v5
v4
e9
Each of the v i are vertices and the ei are the edges.
In this example, the single point v1 is called a vertex.
( v1 , v 2 ) is an edge and is written as e1 = ( v1 , v 2 )
Further we say e1 is incident on v1 and v 2 , and also that v1
and v 2 are incident on e1 .
v1 and v 2 are incident on the same edge e1 so v1 and v 2
are said to be adjacent vertices.
Similarly, e1 and e2 are each incident on v 2 , and so e1 and
e 2 are said to be adjacent edges.
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.
Thus to determine a graph a set of vertices and a set of
edges is required. To determine a set of edges a set of pairs
of vertices is required
1.2.2.
Parallel Edges.
If two distinct edges have the same pair of endpoints, then
the edges are said to be parallel.
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
WUCT121
e1
Graphs
4
Exercises:
Š Draw a graph which has 4 vertices, 1 loop and one pair
of parallel edges. Write down one pair of adjacent vertices
and one pair of adjacent edges.
e1
e2
v2
v1
e3
v4
e5
e4
v3
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
e2
v1
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
e1
v4
v1
e2
v3
e3
e6
e4
v2
Yes
Notes:
∗
There is no ‘vertex of intersection’. In the previous
graph G1 , where the edges e5 and e6 cross is not a vertex.
∗
The vertices determine the edges.
∗
Parallel loops are loops incident on the same vertex.
∗
A vertex without any edges is called an isolated
vertex.
∗
A graph need not be connected, that is, it need not
be in ‘one piece’.
WUCT121
Graphs
7
Exercises:
Š Draw a graph which has 6 vertices, 1 pair of parallel
loops, 1 pair of parallel edges, one isolated vertex and
which is made up of 3 ‘pieces’ or ‘components’.
e1
v3
e2
e5
v1
e4
e3
v6
v5
WUCT121
v2
e6
Graphs
v4
8
1.2.4.
Degree.
The degree of a vertex v, written δ (v ) , is the number of
edges incident on v.
Notes:
∗
If v is a vertex with a single loop as its edge, then
δ ( v ) = 2 . The reason for this convention is that each edge
other than a loop is incident on 2 vertices. So, for
consistency, the single vertex of a loop should be thought
as both starting and ending point for the loop.
∗
Each loop incident on vertex v will contribute 2 to
the value of δ (v ) .
Example:
Š What is the degree of v1 in the following graph?
e2
e1
v2
v1
e3
v3
δ ( v1 ) = 4
WUCT121
Graphs
9
Exercises:
Š Write down the degree of each of the vertices in the
following graphs:
v1
v4
e5
e6
e4
e3
e1
e2
v3
v2
δ (v1 ) = 1, δ (v2 ) = 4, δ (v3 ) = 4, δ (v4 ) = 3
e1
e2
v1
e3
e5
v4
v5
v2
e6
v6
e4
v3
δ (v1 ) = 5, δ (v 2 ) = 3, δ (v3 ) = 2, δ (v 4 ) = 0,
δ (v5 ) = 1, δ (v6 ) = 1
WUCT121
Graphs
10
Š For each of the above graphs calculate
k
∑
i =1
δ (vi ) , where
k = 4 in the first graph and k = 6 in the second
k
4
i =1
i =1
The first graph, ∑ δ (vi ) = ∑ δ (vi ) = 12 .
k
6
i =1
i =1
The second graph, ∑ δ (vi ) = ∑ δ (vi ) = 12
Note:
The first graph was a connected graph and
4
∑ δ (vi ) = 2 × 6 = 12 = 2 × number of edges .
i =1
The second graph is disconnected and
6
∑ δ (vi ) = 2 × 6 = 12 = 2 × number of edges .
i =1
Is this formula always true?
WUCT121
Graphs
11
1.3.
Euler’s Laws
1.3.1.
Euler’s First Law
In any graph, the sum of the degrees of the vertices equals
twice the number of edges.
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.
The number ∑ δ (v ) is sometimes called the total degree of
v∈V
G.
Euler's First Law could be summarised ∑ δ (v ) = m(E ) × 2 ,
v∈V
where m(E ) is the number of edges of the graph.
Exercises:
Š Draw a graph with 4 vertices having degrees 1, 2, 0 and
2.
Since
WUCT121
4
∑
i =1
δ (vi ) = 5 (an odd number), this is not possible
Graphs
12
1.3.2.
Euler’s Second Law
In any graph, the number of vertices which have odd
degree is even
Exercises:
Š Draw some different graphs each with 3 vertices having
degrees 1, 2 and 3.
v2
v1
e1
e2
e3
v3
v2
v1
e1
e3
e2
v3
Š Are these graphs the “same”? No
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.
1.4.1.
Simple Graph
A graph which has neither loops nor parallel edges is called
a simple graph.
Example:
e1
v2
v1
e2
v4
e3
v3
Exercises:
Š Draw a simple graph with 3 vertices having degrees 1,
2 and 3.
Not possible
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
That is, H is a sub-graph of G if each of the vertices of H is
a vertex of G, and each of the edges of H is an edge of G.
Every graph G is a sub-graph of G.
1.4.3.
Proper Sub-Graph
Let G = {VG , EG } be a graph.
H = {V H , E H } is said to be a proper sub-graph of G if
1.
VH ⊆ VG and
2.
E H ⊆ EG and
3.
H ≠G
WUCT121
Graphs
15
Exercises:
Š Let G be given by
e5
e1
v4
v1
e2
v3
e3
e6
e4
v2
Draw the sub-graph H = {{v1 , v 2 , v3 , v 4 }, {e3 , e5 , e6 }}
e5
v4
v1
e3
v3
WUCT121
e6
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:
Consider the graph
e5
e1
v4
v1
e2
v3
e3
e6
e4
v2
Suppose we want to walk from v1 (the bar) to v 3 (67.107).
How could we proceed?
One possible path is v1 , e2 , v 2 , e6 , v3 .
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
If we let u = v β 0 and v = v β n then each edge eα i is
defined by: eα i = (v β i −1 , v β i ) , for i = 1K n
Example:
The path v1 , e2 , v 2 , e6 , v3 from the previous has length 2
The path v1 , e1 , v1 , e5 , v4 , e3 , v 2 , e4 , v 4 , e3 , v 2 , e6 , v3 from
the previous has length 6
1.5.2.
Open Path
A path is open if u ≠ v . That is if the path begins and
finishes at different vertices.
Example:
The path v1 , e2 , v 2 , e6 , v3 is open since u = v1 ≠ v3 = v .
The path v1 , e1 , v1 , e5 , v4 , e3 , v2 , e4 , v4 , e3 , v2 , e6 , v3 is open
since u = v1 ≠ v3 = v .
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:
The path v1 , e2 , v 2 , e3 , v4 , e5 , v1 is closed since u = v1 = v .
1.5.4.
Simple Path
Let G = {V , E} be a graph and let u, v ∈ V . A simple path
from u to v is a path which does not contain a repeated edge
nor a repeated vertex.
Examples:
The path v1 , e2 , v 2 , e6 , v3 is simple since no vertices or
edges are repeated.
The path v1 , e1 , v1 , e5 , v4 , e3 , v 2 , e4 , v 4 , e3 , v 2 , e6 , v3 is not
simple since e3 is repeated.
WUCT121
Graphs
19
Exercises:
Consider the graph
e5
e1
v4
v1
e2
v3
e3
e6
e4
v2
Š Write down a simple path from:
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.
The graph G is said to be connected if and only if
∀u, v ∈ V , there exists a path from u to v.
1.6.2.
Connected Component
Let G = {V , E} be a graph. A sub-graph H of G is said to
be a connected component of G if
1.
H is connected, and
2.
there is no connected sub-graph of G which has
H as a proper sub-graph.
Notes:
∗
A graph is connected if and only if it has only one
connected component
∗
Every graph is the union of its connected
components.
WUCT121
Graphs
21
Exercises:
Consider the graph G.
e1
e2
v1
e3
e5
v4
v5
v2
e6
v6
e4
v3
Which of the following graphs are connected components
of G?
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:
Š Draw a connected graph having five vertices of degrees
1, 1, 2, 2, 2.
v1
v2
e1
e2
v3
e3
e4
v5
v4
Š Draw a graph with two connected components, having
five vertices.
v1
v2
e1
e2
v3
e3
v5
WUCT121
v4
Graphs
23
Š For the following graph:
e2
e1
v2
v1
v4
v7
v6
e5
e7
e6
v3
v8
v5
o
e4
e3
Write down the connected components
H1 = {{v1 , v2 , v3}, {e1 , e2 , e3 , e4 }}
H 2 = {{v4 , v5 , v6 }, {e5 , e6 }}
H 3 = {{v7 , v8 }, {e7 }}
o
Write down two simple paths from v1 to v3 and
one that is not simple.
Simple: v1, e2 , v2 , e3 , v3 and v1 , e2 , v2 , e4 , v3
Not simple: v1 , e1 , v1 , e2 , v2 , e3 , v3
o
List two pairs of vertices that are not connected.
v 2 and v 4 , v6 and v8
WUCT121
Graphs
24
1.7.
Isomorphic Graphs
Example:
Consider the following graphs, are they the isomorphic, i.e.
the “same”?
Š
No. The left-hand graph has 5 edges; the right hand graph
has 6 edges.
WUCT121
Graphs
25
Š
Firstly, label the graphs. It “looks” true, so check all the
things we know:
v'1
v1
v5
v2
v' 4
v4
v' 3
v' 2
v3
v' 5
G′
G
Number of vertices: both 5.
Number of edges: both 5.
Degrees of corresponding vertices: all degree 2.
Connectedness: Each is fully connected.
Number of connected components: Both 1.
Pairs of connected vertices: All correspond.
Number of loops: 0.
Number of parallel edges: 0.
Everything is equal and so the graphs are isomorphic.
WUCT121
Graphs
26
More formally:
G = {V , E} where V = {v1 , v 2 , v3 , v 4 , v5 } and
E = {( v1 , v 2 ), ( v 2 , v3 ), ( v3 , v4 ), ( v 4 , v5 ), ( v5 , v1 )}
= {e1 , e2 , e3 , e4 , e5 }
G ′ = {V ′, E ′} where V ′ = {v1′ , v 2′ , v3′ , v 4′ , v5′ } and
E ′ = {( v1′ , v 2′ ), ( v 2′ , v3′ ), ( v3′ , v 4′ ), ( v 4′ , v5′ ), ( v5′ , v1′ )}
.
′
′
′
′
′
{
}
= e1 , e2 , e3 , e4 , e5
Construct 2 functions: f : V → V ′ and g : E → E ′
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
Let G = {V , E} and G ′ = {V ′, E ′} be graphs. G and G ′ are
said to be isomorphic if there exist a pair of functions
f : V → V ′ and g : E → E ′ such that f associates each
element in V with exactly one element in V ′ and vice versa;
g associates each element in E with exactly one element in
E ′ and vice versa, and for each v ∈V , and each e ∈ E , if v
is an endpoint of the edge e, then f ( v ) is an endpoint of the
edge g ( e) .
Notes:
∗
To prove two graphs are isomorphic you must give
a formula (picture) for the functions f and g.
∗
If two graphs are isomorphic, they must have:
-
the same number of vertices
-
the same number of edges
-
the same degrees for corresponding vertices
-
the same number of connected components
-
the same number of loops
WUCT121
Graphs
28
∗
the same number of parallel edges.
Further,
-
both graphs are connected or both graphs are not
connected, and
-
pairs of connected vertices must have the
corresponding pair of vertices connected.
∗
In general, it is easier to prove two graphs are not
isomorphic by proving that one of the above properties
fails.
WUCT121
Graphs
29
Exercises:
Š Show that the following graphs are isomorphic.
These two graphs each have
-
4 vertices
-
6 edges
-
vertices of degree 1, 3, 4 and 4
-
1 connected component
-
1 loop
-
1 pair of parallel edges
The graphs can be labelled to illustrate their
isomorphism:
v1 e2
e1
e3
e4
v' 4
v2
e5
v' 2
e' 6
e' 2
e' 4
e' 5
e'1
v4
e6
v'1 e' 3 v' 3
v3
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
e1
v1
e2
v2
v1
e1
e1
v2
e1
v2
v1
e2
v2
e2
e2
Since isomorphic graphs are “essentially the same”, we can
use this idea to classify graphs.
WUCT121
Graphs
31
1.8.
Regular, Complete and Complete
Bipartite.
1.8.1.
Definition: Regular.
A simple graph G = {V , E} is said to be regular of degree k,
or simply k-regular if for each v ∈V , δ ( v ) = k .
That is, if a graph is k-regular, every vertex has degree k.
Exercises:
Š Draw all 0-regular graphs with
1 vertex; 2 vertices; 3 vertices.
1 vertex:
2 vertices:
3 vertices:
• v1
• v1
• v1
• v2
• v2
• v3
Š Draw all 1-regular graphs with
1 vertex; 2 vertices; 3 vertices; 4 vertices.
1 vertex and 3 vertices not possible
2 vertices
v1
WUCT121
4 vertices
v2
v1
v2
v3
v4
Graphs
32
Š Draw all 2-regular graphs with 2 vertices; 3 vertices; 4
vertices.
2 vertices, not possible,
∑ δ (v ) = 2 × 2 = 4
v∈V
∴ 2 × n( E ) = 4, n( E ) = 2, thus need parallel edges
3 vertices
4 vertices
v1
v1 v 2
v3 v4
v 2 v3
1.8.2.
Definition: Complete.
A simple graph G = {V , E} is said to be complete if each
vertex of G is connected to every other vertex of G.
The complete graph with n vertices is denoted K n .
Notes:
∗
A complete graph is connected
∗
∀n ∈  , two complete graphs having n vertices are
isomorphic
∗
For complete graphs, once the number of vertices is
known, the number of edges and the endpoints of each edge
are also known
WUCT121
Graphs
33
Example:
Draw K 5
v1
v5
v2
v4
v3
Exercises:
Š Draw K1 , K 2 , K 3 and K 4 . What is the degree of each
vertex in each of the graphs drawn?
K 1 :δ ( v i ) = 0
• v1
K 3 : δ ( vi ) = 2
v1
v 2 v3
WUCT121
K 2 : δ ( vi ) = 1
v1
v2
K 4 : δ ( vi ) = 3
v1
v3
v2
v4
Graphs
34
Š Complete the following sentences:
o
A complete graph, K n , is an ( n − 1) -regular
graph.
o
A complete graph, K n , has 1 n( n − 1) edges.
2
[Use Euler’s First Law:
∑δ
v∈V
(v ) = 2n(E ).]
Since K n has n vertices each of degree (n − 1),
∑δ
v∈V
(v ) = n(n − 1)
∴ 2n(E ) = n(n − 1)
∴ n(E ) = 1 n(n − 1)
2
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 = 
2.
every edge of G connects a vertex in U with a
vertex in W .
Notes:
∗
A bipartite graph G = {V , E} is one whose vertices
can be separated into two disjoint sets, where every edge
joins a vertex in one set to a vertex in the other
∗
∀u ∈ U , δ (u ) ≤ n(W ) and ∀w ∈ W , δ ( w) ≤ n(U )
[ n(W ) is the number of elements in W]
WUCT121
Graphs
36
Example:
Consider the following graph G = {V , E}, where
V = {u1 , u 2 , w1 , w2 , w3 } , is it bipartite? Yes
u1
u2
e2
e1
w1
e4
e3
w2
w3
List the sets U and W. U = {u1 , u 2 }; W = {w1 , w2 , w3 }
Exercises:
Š Consider the following graphs, are they bipartite? If so
write down the sets U and W.
o
WUCT121
u1
u2
e1
e2
w1
w2
U = {u1 , u 2 }; W = {w1 , w2 }
Graphs
37
o
u1
w2
w1
u2
U = {u1 , u2 }; W = {w1 , w2 }
Š Draw two bipartite graphs with 5 vertices.
o Where U has 1 element and W has 4 elements.
u1
w1
w2
w3
w4
o Where U has 2 elements and W has 3 elements.
u1
w1
WUCT121
w2
u2
w3
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
2.
every vertex in U is connected to every vertex in
W.
Notes:
∗
A complete bipartite graph is one whose vertices
can be separated into two disjoint sets where every vertex
in one set is connected to every vertex in the other but no
vertices within either set are connected.
∗
The symbol K n, m is used to denote the complete
bipartite graph having n vertices in one set and m in the
other. [Note that the comma is necessary!]
∗
∀u ∈ U , δ (u ) = n(W ) and ∀w ∈ W , δ ( w) = n(U )
∗
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
Yes:
u2
w2
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?
Does it depend on where you start?
Could you do it with less bridges?
Could you do it with more bridges?
Problem 2:
The Koenigsberg Bridge Problem.
WUCT121
Graphs
42
Can you stroll around, crossing each bridge exactly once
and return to your starting point?
No one can do it.
How do you prove it can't be done?
If you're Leonhard Euler, you make some definitions, make
the problem precise and prove a theorem!
Redraw the problem as a graph:
1.9.1.
Definition: Circuit.
Let G = {V , E} be a graph and let v ∈ V . A circuit in G is a
path from v to v in which no edge is repeated.
Note: A circuit is a closed path and in many books is called
a cycle.
WUCT121
Graphs
43
Exercises:
Š Write down the circuits in the following graph, starting
at the given vertices.
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.
1.9.2.
Definition: Eulerian Path
Let G = {V , E} be a graph. A path in G is an Eulerian path
if every edge of G is included once and only once in the
path.
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.
1.9.4.
Definition: Eulerian Graph
Let G = {V , E} be a graph. G is an Eulerian graph if G has
an Eulerian circuit.
Exercises:
Š Which of these graphs are Eulerian?
K3
K4
v1
v1
v3
v 2 v3
v2
v4
Yes
No
v1
v5
v4
K5
WUCT121
v2
K 2, 3
v3
No
Yes
Graphs
45
Š Can you find an Eulerian path in the following graph
that is not an Eulerian circuit?
e1
v1
e2
v2
e6
e4
v5
v4
v3
e3
e5
v 4 , e3 , v3 , e2 , v 2 , e4 , v 4 , e5 , v5 , e6 , v1 , e1 , v 2
Š Is the graph Eulerian?
No.
In the Koenisberg Bridge Problem, we wanted to start and
end at the same vertex. That is, we need to prove that the
graph K is not Eulerian. How?
1.9.5.
Theorem: Euler's Theorem.
Let G be a connected graph. G is an Eulerian graph if and
only if the degree of each vertex is even.
WUCT121
Graphs
46
For the Koenisberg Bridge Problem:
δ (C ) = 3 , so the graph is not Eulerian.
Discussion:
Is the “connectedness” condition in Euler's Theorem
necessary?
Consider the graph
Each vertex has even degree but there is no Eulerian
circuit.
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?
1.9.6.
Theorem: Existence of Eulerian Path.
A connected graph has an Eulerian path, which is not a
circuit, if it has exactly two vertices of odd degree.
Example:
δ ( A) = 3 ; δ ( B ) = 5 ; δ (C ) = 3 ; δ ( D) = 3
There are more than 2 vertices of odd degree; therefore, K
does not have an Eulerian path.
WUCT121
Graphs
48
1.10.
Trees and Spanning Trees.
1.10.1. Definition: Tree.
A tree is a connected graph which has no non-trivial
circuits.
Notes:
∗
In a graph, a path consisting of a single vertex is a
trivial circuit.
∗
A graph is a tree if and only if it is circuit free and
connected.
∗
A tree can contain a trivial circuit, thus a single
vertex is a tree.
Exercise:
Which of these graphs are trees?
G1 , G4 , G6
WUCT121
Graphs
49
Trees can be used in conjunction with connected graphs.
1.10.2. Definition: Spanning Tree.
A spanning tree for a graph G is a sub-graph of G which is
a tree that includes every vertex of G.
Notes.
∗
A spanning tree of a graph G is a “maximal” tree
contained in the graph G.
∗
When you have a spanning tree T for a graph G, you
cannot add another edge of G to T without producing a
circuit.
Exercises:
Š Can you have a spanning tree for a graph that is not
connected?
No, by definition, a tree is connected.
Š Does every connected graph have a spanning tree?
Yes.
Š Are spanning trees unique in each graph?
No.
WUCT121
Graphs
50
Š If not, do two spanning trees for the same graph have
anything “in common”?
They have the same number of edges.
Š Find all spanning trees for the following graph. (There
are 12)
WUCT121
Graphs
51
Example:
Consider the following graph, G, representing pairs of
people (A, B, C, D and E) who are acquainted with each
other.
B
C
G:
E
A
D
We wish to install the minimum number of phone lines so
that communication between these people is maintained. As
an adviser, you need to find a spanning tree T for G.
C
B
C
B
E
A
D
T1
C
B
E
A
D
T2
E
A
D
T3
How many edges does each tree have? 4
Note:
Any two spanning trees will have the same number of
edges.
WUCT121
Graphs
52
To make the problem more practical:
Suppose the cost involved in installing each line is not the
same. How do you find the network having the least cost?
Begin by putting the cost (in $100) along each edge.
This results in a weighted graph.
B
3
C
5
G:
3.5
A
1
3
E
D
Calculating the cost for each tree:
T1 = 3 + 5 + 3.5 + 1 = 12.5
T2 = 3 + 5 + 3.5 + 3 = 14.5
T3 = 3 + 1 + 3 + 5 = 12
The tree with the lowest “cost" is called the minimum
spanning tree.
In this case, the minimum spanning tree is T3 .
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.
1.10.3. Definition: Weighted Graph
A weighted graph is a graph for which each edge has an
associated real number, called the weight of the edge.
The sum of the weights of all of the edges is the total
weight of the graph.
A minimum spanning tree for a weighted graph is a
spanning tree that has the least possible total weight when
compared with all other spanning trees for the graph.
Note. If G is a weighted graph and e is an edge, then we
will use w(e) to represent the weight of the edge e and w(G)
to represent the total weight of the graph G.
WUCT121
Graphs
54
1.10.4. Kruskal's Algorithm
Example.
Find the minimal spanning tree for the following connected
weighted graph G.
The starting point of Kruskal's Algorithm is to make an
“edge” list, in which the edges are listed in order of
increasing weights.
WUCT121
Graphs
55
Kruskal's Algorithm then includes the 3 additional columns
as follows:
The minimum spanning tree is drawn below.
Note that there are 4 edges in the minimum spanning tree.
If the weighted connected graph G has n vertices, then the
minimum spanning tree will always have n − 1 edges.
Knowing this fact, we need not have checked whether the
edges e6 , e7 , e8 in the table included in the example created
a circuit.
WUCT121
Graphs
56
Kruskal's algorithm will always produce a minimum
spanning tree for any connected weighted graph G.
The idea of the Kruskal's algorithm for finding a minimum
spanning tree T of G is:
To examine the edges of G one by one in order of
increasing weight. At each step, the edge being examined is
added to the sub-graph S (which will be made up of the
edges of T), if the addition of this edge to S does not create
a circuit.
After n − 1 edges have been added to S (where n is the
number of vertices), then the edges of S together with the
vertices of the graph G produce the required tree T.
WUCT121
Graphs
57
Kruskal's Algorithm for finding minimum spanning trees
for weighted graphs (Epp's version) is then:
Input: G a connected weighted graph with n vertices.
Algorithm Body:
(Build a sub-graph T of G to consist of all of the vertices of
G with edges added in order of increasing weight. At each
stage, let m be the number of edges of T.)
1.
Initialise T to have all of the vertices of G and no
edges.
2.
Let E be the set of all edges of G and let m = 0 .
(pre-condition: G is connected.)
3.
While ( m < n − 1)
a.
Find an edge e in E of least weight.
b.
Delete e from E.
c.
If addition of e to the edge set of T does not
produce a circuit then add e to the edge set
of T and set m = m + 1
End While (post-condition: T is a minimum spanning tree
for G.)
Output: T (a graph)
End Algorithm
WUCT121
Graphs
58
1.10.5. Theorem: Kruskal’s Output.
When a connected weighted graph is input into Kruskal's
algorithm, the output is a minimum spanning tree.
The need to construct an ordered edge table before the
algorithm begins and the need to check whether a circuit
has been formed are two detriments to the computer
implementation of Kruskal's algorithm.
Exercises:
Š Use Kruskal's algorithm to find a minimum spanning
tree for the following graph. Draw the minimum spanning
tree.
12
v1
7
4
v3
v2
10
2
v4
8
v7
WUCT121
20
5
15
13
v5
18
v6
19
v8
Graphs
59
Weight
Edge
Will adding edge
make circuit?
Cumulative
Action taken
weight of
sub-graph
( v4 , v5 )
2
No
Added
2
( v1 , v3 )
4
No
Added
6
( v2 , v5 )
5
No
Added
11
( v2 , v4 )
7
Yes
Not added
11
( v3 , v7 ) 8
No
Added
19
( v3 , v4 ) 10
No
Added
29
Yes
Not Added
29
( v7 , v8 ) 13
No
Added
42
( v 4 , v8 ) 15
Yes
Not Added
42
( v5 , v8 ) 18
Yes
Not Added
42
( v6 , v8 ) 19
No
Added
61
( v2 , v6 ) 20
Yes
Not Added
61
( v1 , v 2 )
WUCT121
12
Graphs
60
The minimum spanning tree is:
v1
v2
v3
v5
v6
v4
v7
v8
Š Let G be a connected graph. What can you say about an
edge e of G if:
o e is included in every spanning tree for G?
e is not an edge in a circuit in G.
o e is not included in any spanning tree for G?
e is a loop.
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:
Can either of these graphs be drawn with no incidental
crossings?
Š
v1′
K4 :
v1
v3
v2
v4
Yes
v3′
v4′
v2′
Š
K 3, 3
WUCT121
No
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:
∗
A plane graph divides the plane into distinct
“regions” called faces.
∗
The “outside” of a plane graph is always considered
a face.
Exercises:
Number the faces in these graphs.
Š
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:
∗
A plane graph is a connected planar graph.
1.11.3. Theorem: Euler's Plane Graph Theorem.
If G = {V , E} is a plane graph and if v equals the number of
vertices, e equals the number of edges, and f equals the
number of faces, then v − e + f = 2 .
Exercises:
Check Euler's Plane Graph Theorem for these graphs
Š
1
3
2
WUCT121
v = 4, e = 5, f = 3
v −e+ f = 4−5+3= 2
Graphs
64
Š
1
4
3
2
v = 5, e = 7, f = 4
v −e+ f = 5−7+4 = 2
Š
Re-draw so that there are no edges crossing:
2
1
3
4
v = 4, e = 6, f = 4
v−e+ f = 4−6+4 = 2
The problem with applying this Theorem is that the graph
has to be drawn as a plane graph before it can be applied.
It does not help us decide if K 3, 3 is a planar graph.
WUCT121
Graphs
65
The following theorem includes a condition which can be
checked in the original graph.
1.11.4. Theorem: Conditions of a Plane Graph.
If G = {V , E} is a plane graph, without loops or parallel
edges, v = n(V ) , e = n(E ) and v ≥ 3 , then
1.
e ≤ 3v − 6 , AND
2.
if every circuit has at least 4 edges then
e ≤ 2v − 4 .
If the conditions of this theorem are also satisfied in any
simple graph, G, then G may or may not be a planar graph.
However, if they are not satisfied, then G is not a planar
graph.
WUCT121
Graphs
66
Exercises:
Š Check the conditions for a plane graph for the
following graph.
1. Check e ≤ 3v − 6
e = 14, v = 8
3v − 6 = 18
∴ e < 3v − 6
2. All circuits have at least 4 edges.
Check all the circuits and that e ≤ 2v − 4 .
2v − 4 = 12
∴ e > 2v − 4
Therefore we do not have a planar graph.
WUCT121
Graphs
67
Š Decide whether these graphs are planar.
o
K 3, 3
1. Check e ≤ 3v − 6
e = 9, v = 6
∴ 3v − 6 = 12
∴ e < 3v − 6
2. All circuits have at least 4 edges.
Check that e ≤ 2v − 4 .
2v − 4 = 8
∴ e > 2v − 4
Therefore this graph is not planar.
WUCT121
Graphs
68
o
v1
v2
v3
v4
v5
v6
v7
Check e ≤ 3v − 6
1.
e = 11, v = 7
∴ 3v − 6 = 15
∴ e < 3v − 6
2. Some circuits have three edges.
From this, we do not know whether the graph is
planar or not.
3. Re-drawing the graph, we find it is planar.
v1′
v3′
v5′
v7′
v6
v 4′
v2′
WUCT121
Graphs
69
o
v1
v5
v2
v4
v3
This is the complete graph K 5
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.
Further, a graph is non-planar if and only if it contains K 3, 3
or K 5 as a sub-graph.
Example:
v5
v2
v3
v8
v6
v1
v4
v7
The graph does not have 6 vertices of degree 3 and so
cannot contain K 3, 3 .
The graph does not have 5 vertices of degree 4 and so
cannot contain K 5 .
WUCT121
Graphs
71
Redrawing the graph without crossings:
v3′
v 2′
v5′
v7′
v1′
v 4′
v6′
v8′
v = 8, e = 11, f = 5
v − e + f = 8 − 11 + 5 = 2
WUCT121
Graphs
72