Topic 5 Lecture Notes (Gardiner)
Topic 5 Lecture Notes (Gardiner)
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 1/17
Graphs
Definition. A graph G is a mathematical object consisting of two related
sets:
• The vertex set of G , written as V (G ) or just V , is a set of vertices (often
labelled v1 , v2 , v3 , ... ).
• The edge set of G , written as E (G ) or just E , is a set of edges
(sometimes labelled e1 , e2 , e3 , ... ). Each edge is itself a subset of V (G )
with cardinality 2, representing the two vertices it connects, which are
known as the edge’s endpoints.
Notice that since each edge is a set of cardinality 2, no edge can have a
single vertex as both of its endpoints in a graph.
Notice also that since E (G ) is a set, there can be at most one edge between
any two distinct vertices in a graph.
Notation. An edge with endpoints v and w is written as {v , w }, but is
more often represented by the shorthand vw , or equivalently, wv .
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 2/17
Representing graphs
Graphs can be represented diagrammatically as dots (vertices) joined by
connecting line or curve segments (edges). The relative positions of the
vertices and edges do not matter.
For example, the graph G with vertex set V (G ) = {a, b, c, d} and edge set
E (G ) = {ab, ac, ad, bc, cd} can be represented by any of these diagrams:
a b b d b
d c a c c a
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 4/17
Representing multigraphs
Multigraphs can be represented diagrammatically in the same way as graphs.
For example, the multigraph G with vertex set V (G ) = {a, b, c}, edge set
E (G ) = {e1 , e2 , e3 , e4 }, and endpoint function
f = { (e1 , {a, b}), (e2 , {b, c}), (e3 , {b, c}), (e4 , {a}) }
c e3
Notice that all graphs are multigraphs, with the restrictions that the
endpoint function cannot map any edge to a single vertex, nor map any two
distinct edges to the same pair of vertices.
Definition. A simple multigraph is a multigraph without any loops or
parallel edges. That is, a simple multigraph is a graph.
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 5/17
Directed graphs
Definition. A directed graph G is a mathematical object consisting of two
related sets:
• The vertex set V (G ) is a set of vertices.
• The edge set E (G ), for which each edge is an ordered pair of distinct
vertices of G , representing the edge’s start and end vertices in order.
Definition. A directed multigraph G is a mathematical object consisting of
two sets and a function:
• The vertex set V (G ) is a set of vertices.
• The edge set E (G ) is a set of edges.
• The endpoint function f : E (G ) → V (G ) × V (G ) is a function mapping
edges of G to ordered pairs of vertices.
When representing a directed (multi)graph diagrammatically, each edge is
represented by an arrow pointing from its start vertex to its end vertex.
For example, the arrow diagram for a function f : X → Y is a directed
graph, and the arrow diagram for a relation R on X is a directed multigraph.
The Hasse diagram for any poset is also a directed graph, since all its edges
are technically directed upwards.
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 6/17
Special graphs: Path graphs
Most of the Topic 5 content is focused specifically on graphs, as opposed to
multigraphs or directed (multi)graphs.
Some graphs are common or useful enough that they have special names.
We will define several such named graphs in terms of labelled vertices,
though they are often also interpreted as being unlabelled.
Definition. The path graph on n ≥ 1 vertices, written as Pn , is the graph
with vertex set V (Pn ) = {v1 , v2 , ... , vn } and edge set
For example,
v1 v2 v1 v2 v3 v1 v2 v3 v4
P2 P3 P4
For example,
v2
v1 v1 v2
v1 v3
v3 v2 v4 v3 v5 v4
C3 C4 C5
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 8/17
Special graphs: Complete graphs
Definition. The complete graph on n ≥ 1 vertices, written as Kn , is the
graph with vertex set V (Kn ) = {v1 , v2 , ... , vn } and edge set
E (Kn ) = { {v , w } ⊆ V (Kn ) : v ̸= w } = {vi vj : 1 ≤ i < j ≤ n}.
That is, the complete graph Kn is the graph with n vertices and all possible
edges between these vertices. For example,
v2
v1 v1 v2
v1 v3
v3 v2 v4 v3 v5 v4
K3 K4 K5
V2
v4 v3 v2 v4
v2 w2
v3 w3
w1 w2 w3 w1 w2 w3 w4
K2,3 K3,3 K1,4
100 101
0 1 00 01 000 001
Q1 Q2 Q3
d c d c c
G G′ G ′′
Notice that:
• For every integer n ≥ 3, we have that Pn is a subgraph of Cn .
• For any n ∈ Z+ , the (unlabelled) cube graph Qn is a subgraph of the
cube graph Qm for all integers m ≥ n.
• Every (unlabelled) graph with n vertices is a subgraph of Kn , and indeed
a subgraph of Km for all integers m ≥ n.
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 14/17
Example – Finding subgraphs
Example. How many subgraphs are there of the graph G with vertex set
V (G ) = {a, b, c} and edge set E (G ) = {ab, ac, bc}?
Solution. Let H be a subgraph of G . We consider different cases for
different sizes of V (H).
• If V (H) = {a, b, c}, then E (H) ⊆ {ab, ac, bc}, so there are 23 = 8
possible values for E (H).
• If V (H) = {a, b}, then E (H) ⊆ {ab}, so there are 21 = 2 possible values
for E (H). Similarly, there are two subgraphs with V (H) = {a, c} and
with V (H) = {b, c}.
• If V (H) = {a}, then E (H) ⊆ {}, so there is 20 = 1 possible value for
E (H). Similarly, there is one subgraph with V (H) = {b} and with
V (H) = {c}.
• If V (H) = {}, then E (H) ⊆ {}, so there is 1 possible value for E (H).
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 15/17
Example – Finding unlabelled subgraphs
Example. How many subgraphs are there of the unlabelled cyclic graph C3 ?
Solution. In this case, it is easier to simply list the subgraphs. They are:
• Subgraphs with exactly 3 vertices:
, , ,
• Subgraphs with exactly 2 vertices:
,
• Subgraphs with exactly 1 vertex:
(empty graph)
So there are 4 + 2 + 1 + 1 = 8 subgraphs of the unlabelled cyclic graph C3 .
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 16/17
Graph complement
Definition. The complement of a graph G , written as G , is the graph with
the same vertex set as G , but with an edge set whose edges have endpoints
v and w if and only if vw ̸∈ E (G ). That is, V (G ) = V (G ) and
E (G ) = E (Kn ) − E (G ) where n = |V (G )|.
Note the graph complement is so-called because if a graph G has n vertices,
then setting the universal set of edges to be U = E (Kn ), we have that
E (G ) = (E (G ))c .
For example, a graph G and its complement G are:
a b a b
d c d c
MATH1081 Topic 5 – Graph theory Lecture 5.01 – Graph and multigraph terminology 17/17
MATH1081 – Discrete Mathematics
Topic 5 – Graph theory
Lecture 5.02 – Vertex degree and isomorphisms
3 + 2 + 3 + 2 = 2 × 5. 2 + 3 + 2 + 2 + 1 = 2 × 5. 3 + 3 + 2 = 2 × 4.
Example. How many edges does Qn have?
Solution. We have seen that |V (Qn )| = 2n and that the degree of each
vertex in Qn is n. So by the handshaking lemma, we have
1 X 1
|E (Qn )| = deg(v ) = (n2n ) = n2n−1 .
2 2
v ∈V (Qn )
MATH1081 Topic 5 – Graph theory Lecture 5.02 – Vertex degree and isomorphisms 2/11
Degree sequences
Definition. A vertex degree sequence of a (multi)graph is a sequence of the
degrees of all vertices of the graph. It is usually written in increasing or
decreasing order.
Example. Does a graph or multigraph with the vertex degree sequence
3, 3, 2, 2, 2, 1 exist?
Solution. If such a multigraph existed, its vertex degree sum would be
3 + 3 + 2 + 2 + 2 + 1 = 13, which is odd. But by the handshaking lemma,
this total must be even, since it should equal twice the number of edges in
the multigraph. So no such multigraph exists.
Fact. No multigraph has a vertex degree sequence whose sum is odd.
Proof. This is a direct result of the handshaking lemma.
Fact. Every multigraph has an even number of vertices of odd degree.
Proof. If a multigraph had an odd number of vertices of odd degree, its
vertex degree sum would be odd, which is impossible.
MATH1081 Topic 5 – Graph theory Lecture 5.02 – Vertex degree and isomorphisms 3/11
Example – Degree sequences
Example. Does a graph or multigraph with the vertex degree sequence
4, 3, 3, 3, 3 exist?
Solution. One such graph (which is also a multigraph) is given below.
MATH1081 Topic 5 – Graph theory Lecture 5.02 – Vertex degree and isomorphisms 4/11
Degree sequences for graphs and multigraphs
Fact. Not every vertex degree sequence whose sum is even has a
corresponding graph.
Fact. Every vertex degree sequence whose sum is even has a corresponding
multigraph.
Proof. Since the vertex degree sum is even, there must be an even number
of vertices of odd degree. Partition the vertices of odd degree into pairs, and
construct a single edge between each pair. All vertices now have degree that
differs from their expected degree by an even number. If a vertex has degree
differing from its expected degree by 2k for some integer k, construct k
loops at that vertex. Once completed, we have constructed a multigraph
with the required vertex degree sequence.
Example. Find multigraphs with the following degree sequences.
4, 4, 4, 2, 2. 5, 3, 3, 2, 1.
MATH1081 Topic 5 – Graph theory Lecture 5.02 – Vertex degree and isomorphisms 5/11
Graph isomorphism
We have seen that graphs can be represented diagrammatically in many
different ways, but are always considered the same graph. We might also
wish to treat two graphs that have the same shape but different vertex or
edge labellings as equivalent in some way, like the following examples:
a b p q w
x
d c s r y z
Definition. Two graphs G and H are isomorphic, written G ≃ H, if and
only if there exists a bijective function f : V (G ) → V (H) such that vertex
adjacency is preserved, that is, for all v , w ∈ V (G ), we have that
{v , w } ∈ E (G ) if and only if {f (v ), f (w )} ∈ E (H).
Equivalently, G ≃ H if and only if there exists a bijective function
f : V (G ) → V (H) such that V (H) = f (V (G )) and
E (H) = { {f (v ), f (w )} : {v , w } ∈ E (G ) } .
If two graphs are isomorphic, we call the function f a graph isomorphism.
Graph isomorphism is an equivalence relation on the set of all graphs.
MATH1081 Topic 5 – Graph theory Lecture 5.02 – Vertex degree and isomorphisms 6/11
Example – Isomorphic graphs
To prove that two graphs are isomorphic, we must provide a graph
isomorphism between them.
Example. Prove that the following two graphs are isomorphic.
a b w
x
d c y z
G1 G2
f c
e d x y z
G1 G2
MATH1081 Topic 5 – Graph theory Lecture 5.02 – Vertex degree and isomorphisms 9/11
Example – Non-isomorphic graphs
To prove that two graphs are not isomorphic, we can identify an invariant
property that one graph has and the other does not.
Example. Prove that the following two graphs are not isomorphic.
b w
a c v x
e d z y
G1 G2
MATH1081 Topic 5 – Graph theory Lecture 5.02 – Vertex degree and isomorphisms 10/11
Example – Non-isomorphic graphs
Example. Are the following two graphs isomorphic?
b v w
a c
e x y z
d
G1 G2
v1 v2
1 0 1 1
0 0 0 0
For example, has adjacency matrix
1
.
0 0 2
1 0 2 0
v4 v3
Notice that any adjacency matrix for a graph can only have entries that are
0 or 1 (since there are no parallel edges), and every entry on the main
diagonal must be 0 (since there are no loops).
Notice that an adjacency matrix A = (ai,j ) for any (multi)graph must be
symmetric, that is, ai,j = aj,i for all i, j. (An adjacency matrix for a directed
(multi)graph might not be symmetric.)
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 3/18
Counting walks
Recall that the product of the n × n matrices A = (ai,j ) and B = (bi,j ) is the
matrix C = (ci,j ) whose entries are given by
n
X
ci,j = ai,k bk,j = ai,1 b1,j + ai,2 b2,j + · · · + ai,n bn,j .
k=1
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 7/18
Cycles in bipartite graphs
Theorem. A (multi)graph G is not bipartite if and only if it contains a cycle
of odd length.
Equivalently, a (multi)graph G is bipartite if and only if every cycle in G has
even length.
Proof of forward implication. First suppose G is a bipartite multigraph
with vertex set partitions V1 and V2 . Then any walk in G must alternate
vertices between V1 and V2 . So for any cycle in G , since it must start and
end in the same vertex partition, its length must be even.
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 8/18
Cycles in bipartite graphs
Proof of backward implication. Now suppose that G is a multigraph for
which every cycle in G has even length. For simplicity, we shall assume G is
connected – if it is not, a similar approach can be applied to each connected
component of G .
Choose some vertex w in G , and construct the sets
V1 = {v ∈ V (G ) : there is a path in G from v to w of even length},
V2 = {v ∈ V (G ) : there is a path in G from v to w of odd length}.
Certainly V1 ∪ V2 = V (G ), since every vertex must be either an odd or even
distance from a particular vertex in a connected graph. We also have that
V1 ∩ V2 = ∅, since if there were some vertex v ∈ V1 ∩ V2 , then there would
exist a path P1 from v to w of even length, and a path P2 from v to w of
odd length, meaning the walk P1 P2−1 would be a cycle of odd length, which
is not possible in G . So V1 and V2 partition V (G ).
Furthermore, if two vertices u, v ∈ V1 or u, v ∈ V2 were adjacent, the walk
w ... uv ... w would be a cycle of odd length, which again is not possible in
G . So no two vertices both in V1 or both in V2 are adjacent, meaning G is
bipartite.
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 9/18
Euler walks
Definition. In any connected (multi)graph G , an Euler trail is a trail that
visits each edge of G exactly once, and an Euler tour is a tour that visits
each edge of G exactly once.
For example, consider the following graphs:
b a b a b
a c
e e
e d d c d c
G1 G2 G3
• The graph G1 has an Euler tour, for example abcdeacebda.
• The graph G2 has an Euler trail, for example baedcebc.
• The graph G3 does not have an Euler walk.
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 13/18
Example – Euler walks
Example. Decide whether each graph below has an Euler trail or tour.
a b a b a b
f c f c f c
g g g
e d e d e d
G1 G2 G3
Solution. Since every vertex of G1 has even degree, an Euler tour exists in
G1 . For example, the tour abgcdgefgacea.
Since exactly two vertices of G2 have odd degree (d and e), an Euler trail
exists in G2 , and its start and end points must be at d and e in some order.
For example, the trail degdcgbagfe.
Since more than two vertices of G3 have odd degree (a, b, c, and f ), no
Euler path exists in G3 .
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 14/18
Hamilton walks
Definition. In any connected (multi)graph G , a Hamilton path is a path
that visits each vertex of G exactly once, and a Hamilton cycle is a cycle
that visits each vertex of G exactly once (except for its first and last vertex).
For example, consider the following graphs:
b a b a b
a c
f c f c
g g
e d e d e d
G1 G2 G3
• The graph G1 has a Hamilton path, for example abcde, and a Hamilton
cycle, for example abcdea.
• The graph G2 has a Hamilton path, for example bacefgd, but no
Hamilton cycle.
• The graph G3 does not have a Hamilton walk.
To prove the existence of a Hamilton walk, we can simply construct one. It
is generally difficult to prove non-existence of a Hamilton walk, but we can
still establish some useful partial results.
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 15/18
Properties of Hamilton walks
Unlike for Euler walks, there is no known necessary and sufficient condition
for a graph to contain a Hamilton walk. The following partial results are
provided without proof.
Fact. If any vertex v in a connected (multi)graph G has degree 1, there is
no Hamilton cycle, and if there is a Hamilton path, it must start or end at v .
Fact. If any vertex v in a connected (multi)graph G has degree 2, then
both edges incident with v must be part of a Hamilton cycle if it exists.
Fact. If a Hamilton cycle exists for a (multi)graph G , every vertex of G
must be incident with exactly 2 edges that are used in the walk. If a
Hamilton path exists for a (multi)graph G , exactly two vertices of G must be
incident with exactly 1 edge that is used in the walk, and all other vertices
of G must be incident with exactly 2 edges that are used in the walk.
Theorem. (Dirac) If a graph G with n ≥ 3 vertices has the property that
every vertex has degree at least n2 , then G contains a Hamilton cycle.
Theorem. (Ore) If a graph G with n ≥ 3 vertices has the property that
every pair of non-adjacent vertices has degree sum at least n, then G
contains a Hamilton cycle.
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 16/18
Example – Hamilton walks
Example. Prove that G2 cannot have a Hamilton cycle.
a b
f c
g
e d
G2
Solution. Suppose a Hamilton cycle exists for G2 . Any Hamilton cycle must
pass through both edges incident with each vertex of degree 2. Since b has
degree 2, edges ab and bg must be included in the Hamilton cycle. Since d
has degree 2, edges dc and dg must be included in the Hamilton cycle.
Since f has degree 2, edges fe and fg must be included in the Hamilton
cycle. But this means g is incident with more than 2 edges in the Hamilton
cycle, which is impossible. So no Hamilton cycle exists for G2 .
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 17/18
Example – Hamilton walks
Example. Prove that G3 cannot have a Hamilton walk.
a b
f c
g
e d
G3
MATH1081 Topic 5 – Graph theory Lecture 5.03 – Standard, Euler, and Hamilton walks 18/18
MATH1081 – Discrete Mathematics
Topic 5 – Graph theory
Lecture 5.04 – Planar graphs and maps
MATH1081 Topic 5 – Graph theory Lecture 5.04 – Planar graphs and maps 1/12
Regions
Definition. In any planar map of a planar (multi)graph G , the plane is
divided into regions (often labelled R1 , R2 , R3 , ... ) whose boundaries are the
edges of G . Exactly one of these regions is unbounded, in the sense that it
extends infinitely outside of the planar map.
For example, each of the planar multigraphs below has 3 regions labelled R,
S, and T , and in both cases T is the unbounded region.
R
S
T T S
R
However, regardless of the planar map chosen, we have an analogue for the
handshaking lemma on degrees of regions.
Theorem. (Handshaking lemma for regions)
For any planar (multi)graph G and planar map of G , the sum of the degrees
of all the regions in the planar map equals twice the number of edges in G .
That is, for any planar multigraph G and planar map of G ,
X
deg(R) = 2 |E (G )|.
regions R
MATH1081 Topic 5 – Graph theory Lecture 5.04 – Planar graphs and maps 7/12
Example – Planarity conditions
Example. Show that the graph below is not planar.
a b
f c
g
e d
Solution. The graph is connected, so if it were planar we would require that
e ≤ 3v − 6. However here the graph has v = 7 vertices and e = 16 edges,
so we have 3v − 6 = 15 ̸≥ 16 = e, meaning the graph cannot be planar.
Example. Show that K5 is not planar.
We know that K5 is a connected graph with v = 5 vertices and
Solution.
e = 52 = 10 edges. Since 3v − 6 = 9 ̸≥ 10 = e, we can conclude that K5 is
not planar.
Example. Show that K3,3 is not planar.
Solution. We know that K3,3 is a connected graph with 3 + 3 = 6 vertices
and 3 × 3 = 9 edges. Because K3,3 is bipartite, it has no cycles of odd
length, and so in particular has no cycles of length 3. So since
2v − 4 = 8 ̸≥ 9 = e, we can conclude that K3,3 is not planar.
MATH1081 Topic 5 – Graph theory Lecture 5.04 – Planar graphs and maps 8/12
Kuratowski’s theorem
Definition. A subdivision of a (multi)graph G is a new multigraph G ′ that
has had additional vertices inserted by replacing some edges with
non-intersecting paths of arbitrary length. For example, G1 and G2 below are
subdivisions of G , but G3 is not a subdivision of G .
G G1 G2 G3
We can create any subdivision of a graph G by repeating the following
process: remove an edge uw from E (G ), add a new vertex v to V (G ), and
add new edges uv and vw to E (G ).
Clearly a (multi)graph G is planar iff any subdivision of G is planar.
Theorem. (Kuratowski)
A (multi)graph is planar if and only if it does not contain a subgraph which
is a subdivision of K5 or K3,3 .
While the forward implication is obvious, the backward implication is very
difficult to prove, and so for this course its proof is not provided.
MATH1081 Topic 5 – Graph theory Lecture 5.04 – Planar graphs and maps 9/12
Example – Kuratowski’s theorem
Example. Decide whether the graph below is planar.
a b a b
c h
h
has subgraph g c
g d
d
f e f e
Solution. Consider the subgraph with the edge dh removed. This is a
subdivision of K3,3 , with additional vertices d and h. So the graph is not
planar by Kuratowski’s theorem.
Example. Decide whether the graph below is planar.
a b g
a b
has subgraph f c
f c
g
e d e d
Solution. Consider the subgraph with the edges ag and bg removed. This
is a subdivision of K5 , with additional vertices a and b. So the graph is not
planar by Kuratowski’s theorem.
MATH1081 Topic 5 – Graph theory Lecture 5.04 – Planar graphs and maps 10/12
Dual maps
Definition. Given a planar (multi)graph G and a planar map of G , we can
construct its dual planar map of a multigraph G ∗ by doing the following:
• For each region R in the planar map of G , create a corresponding vertex
vR in the planar map of G ∗ .
• For each vertex v in the planar map of G , create a corresponding region
Rv in the planar map of G ∗ .
• For each edge e in the planar map of G that is incident with regions R
and S and incident with vertices v and w , create a corresponding edge
e ∗ in the planar map of G ∗ that is incident with vertices vR and vS and
incident with regions Rv and Rw .
a b Ra Rb vT
vS
S
T vR vT Rb Rd Ra
R Rc
d c Rd Rc vS vR
∗
G G
MATH1081 Topic 5 – Graph theory Lecture 5.04 – Planar graphs and maps 11/12
Properties of dual maps
Example. Find the dual planar map of the planar map below.
a b vR R a Rb
R Rb
vS vR vT vS
T S Ra Rc
vT
c Rc
G G∗
Fact. Given a planar (multi)graph G and a planar map of G with v vertices,
e edges, and r regions, its dual planar map has r vertices, e edges, and v
regions.
Fact. Given a planar (multi)graph G and a planar map of G , two vertices v
and w are adjacent if and only if their corresponding regions Rv and Rw in
the dual planar map are adjacent.
Fact. Given a planar (multi)graph G , the vertex degree sequence of G is the
same as the region degree sequence for any dual planar map of G ∗ , and the
vertex degree sequence of any dual graph G ∗ is the same as the region
degree sequence for some planar map of G .
MATH1081 Topic 5 – Graph theory Lecture 5.04 – Planar graphs and maps 12/12
MATH1081 – Discrete Mathematics
Topic 5 – Graph theory
Lecture 5.05 – Trees and weighted graphs
G1 G2 G3 G4
Theorem. Any tree with at least one edge contains at least 2 pendant
vertices.
Proof. Suppose G is a tree with at least one edge. Since the edge cannot
be a loop, G must contain a path between two distinct vertices. Find a path
P = v0 v1 ... vn of maximal length in G . Clearly v0 has degree at least 1.
Suppose v0 has degree greater than 1. Then v0 is adjacent to some other
vertex u in G . If u is not part of P, then we can extend P to make a longer
path uv0 v1 ... vn , which contradicts the maximality of P. If u is part of P,
then v0 v1 ... uv0 is a cycle, which contradicts that G is a tree and must
contain no non-trivial cycles. So deg(v0 ) = 1, and by a similar argument we
also have that deg(vn ) = 1, meaning G contains at least 2 pendant vertices.
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 1/11
Number of edges in a tree
Theorem. A connected nonempty multigraph G is a tree if and only if we
have |E (G )| = |V (G )| − 1.
Proof of forward implication. Let P(n) be the statement “Any tree with n
vertices has n − 1 edges”.
The only tree with 1 vertex is the graph with 1 vertex and 0 edges, since it
cannot contain any loops (which are cycles), so P(1) is true.
Next suppose P(k) is true for some positive integer k, and consider a tree G
with k + 1 vertices. Because G is a tree, it contains at least two pendant
vertices, so consider the new graph G ′ formed by removing a pendant vertex
and its incident edge from G . Then G ′ has k vertices, and is also a tree
since it is still connected and contains no cycles. So by the inductive
hypothesis, G ′ has k − 1 edges, meaning the original graph G has k edges.
Thus we have shown P(k) ⇒ P(k + 1), meaning P(n) is true for all n ∈ Z+
by induction.
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 2/11
Number of edges in a tree
Theorem. A connected nonempty multigraph G is a tree if and only if we
have |E (G )| = |V (G )| − 1.
Proof of backward implication. Suppose G is a connected multigraph
with |E (G )| = |V (G )| − 1. Further suppose that G contains a cycle. Then
we may remove this cycle by deleting an edge in the cycle, which reduces the
number of edges by 1 but does not change the number of vertices and does
not disconnect the graph. Repeating this procedure for all cycles in G , we
eventually reach a new graph G ′ that is connected and has no cycles, and is
therefore a tree. By the forward implication proof, we must have
|E (G ′ )| = |V (G ′ )| − 1. But then we have
|E (G )| > |E (G ′ )| = |V (G ′ )| − 1 = |V (G )| − 1,
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 3/11
Spanning trees
Definition. A spanning tree of a (multi)graph G is a tree which is subgraph
of G and which contains all vertices of G . That is, a spanning tree T of a
multigraph G is a tree for which V (T ) = V (G ) and E (T ) ⊆ E (G ).
For example, the following blue graphs are all spanning trees of K4 .
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 4/11
Weighted graphs
Definition. A weighted (multi)graph is a multigraph whose edges are
associated with numbers called weights. Each edge is assigned a particular
number, and typically these numbers are positive and rational or natural.
In general, we can say a weighted multigraph G is a multigraph equipped
with a weight function w : E (G ) → R.
Notation. The weight of an edge e is denoted w (e).
Definition. The weight of a (multi)graph G , sometimes denoted w (G ), is
the sum of all its edge weights. That is,
X
w (G ) = w (e).
e∈E (G )
2 3 1
3 5
4
3 2
For example, the graph above has two minimal spanning trees, each with
weight 8:
2 1 2 3 1
3
2 2
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 6/11
Kruskal’s algorithm
A procedure for finding a minimal spanning tree for any connected weighted
(multi)graph G is Kruskal’s algorithm:
• Begin with a subgraph T with V (T ) = V (G ) and E (T ) = {}.
• Sort the edges in G by increasing weight order.
• For each edge in the ordered sequence, add the edge to E (T ) if its
inclusion will not introduce a cycle in T .
• Once |E (T )| = |V (G )| − 1, the process ends and T is a minimal
spanning tree of G .
Kruskal’s algorithm can be carried out efficiently by filling out a table like
the following, with the edges ordered by increasing weight:
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 7/11
Example – Kruskal’s algorithm
Example. Find a minimal spanning tree for G . a 6 b 3 c
Solution. Applying Kruskal’s algorithm gives: 6 14
5 2
edge ei weight w (ei ) included? 1 5
d f
be 1 yes
3 2 e 2
de 1 yes 4 4
hi 1 yes
cf 2 yes g 5 h 1 i
eh 2 yes
ei 2 no (ehie is a cycle)
G
bc 3 yes
eg 3 yes
ce 4 no (bceb is a cycle)
dg 4 no (degd is a cycle) a b 3 c
fi 4 no (bcfiheb is a cycle)
ad 5 yes 5 1 2
ef 5 no (8 edges have been selected) 1 e
d f
gh 5 no (8 edges have been selected)
ab 6 no (8 edges have been selected) 3 2
ae 6 no (8 edges have been selected)
g h 1 i
Thus a minimal spanning tree (with weight 18) is:
Note that if we had ordered the edges by weight differently, we might have
included ei instead of eh and found a different minimal spanning tree.
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 8/11
Minimal v -path spanning trees
Definition. Given a weighted (multi)graph G and vertices u, v ∈ V (G ), a
shortest path from u to v is a path P from u to v in G with minimal weight
w (P). We call the weight of this shortest path the distance from u to v ,
and write d(u, v ) = w (P).
Definition. Given a weighted (multi)graph G and a vertex v ∈ V (G ), a
minimal v -path spanning tree is a spanning tree T of G in which for every
vertex u ∈ V (G ), the unique path from v to u in T is the shortest path
from v to u in G .
Note that for any weighted (multi)graph G and vertex v in G , a minimal
v -path spanning tree of G is usually not a minimal spanning tree of G . For
example, the graph G on the left has a minimal z-path spanning tree shown
on the right. w w
2 3 1 3 1
u 3 5 x u 3 x
z z
4 4
3 2
y y
So in G , we know d(z, u) = 3, d(z, w ) = 3, d(z, x) = 4, and d(z, y ) = 4.
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 9/11
Dijkstra’s algorithm
A procedure for finding a minimal v -path spanning tree for any connected
weighted (multi)graph G and vertex v ∈ V (G ) is Dijkstra’s algorithm:
• Begin with a tree T with V (T ) = {v } and E (T ) = {}.
• Consider all edges ei ∈ E (G ) that have one endpoint ui ∈ V (T ) and one
endpoint wi ̸∈ V (T ). Out of all these edges, choose the one for which
d(v , ui ) + w (ei ) is minimal, and add ei to E (T ) and wi to V (T ).
• Repeat the previous step until V (T ) = V (G ), at which point the process
ends and T is a minimal v -path spanning tree of G .
Dijkstra’s algorithm can be carried out efficiently by filling out a table like
the following:
MATH1081 Topic 5 – Graph theory Lecture 5.05 – Trees and weighted graphs 10/11
Example – Dijkstra’s algorithm
Example. Find a minimal a-path spanning tree for G . a 2 b 4 c
Solution. Applying Dijkstra’s algorithm gives: 4 14
3 1
possible edges ui wi included included distance 1 3
d f
(weight d(a, ui ) + w (ui wi )) edge ui wi vertex wi d(a, wi )
3 4 e 2
a 0 2 2
ab (2), ad (3), ae (4) ab b 2
ad (3), ae (4), bc (6), be (3) ad d 3 g 2 h 3 i
ae (4), bc (6), be (3), de (4), be e 3 G
dg (5)
bc (6), dg (5), ec (7), ef (6), dg g 5
eg (6), eh (7), ei (5)
bc (6), ec (7), ef (6), eh (7), ei i 5
ei (5), gh (7)
a 2 b 4 c
bc (6), ec (7), ef (6), eh (7), bc c 6
gh (7), if (7), ih (8) 3 1
e 3
cf (7), ef (6), eh (7), gh (7), ef f 6 d f
if (7), ih (8) 2
eh (7), gh (7), ih (8) eh h 7
2 4