2.1 Intorduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.2 Basic Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 Minimal spanning trees . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.5 Euler walks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.6 Vertex Coloring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.1 Intorduction
What is a graph?
A graph is a collection of points and lines connecting some pairs of the points.
The points are called the vertices (singular: vertex).
The lines joining any the vertices are called edges (singular: edge).
Example 2.1.
A B
C
D
Vertices: A, B, C, D, E.
Edges: AB, BD, BE, CD, CE, DE
1
GEH1036: CHAPTER 2 GRAPHING 2
B
A
E
C
D
Two vertices that are joined by an edge are called adjacent vertices.
Later we will also use multiple edges and loops:
a loop multiple edges
Definition 2.2 (Simple graphs). A graph without loops and multiple edges is called
a simple graph.
Applications:
More than half of everyone who shops online has a Facebook profile.
Facebook as a graph:
GEH1036: CHAPTER 2 GRAPHING 3
Vertices = people
C1
C2
C7
C3 C6
C4 C5
Problem: What is the minimum number of warehouses that factory needs in order
to store its chemical products safely?
Problem: Find a trail that uses all the edges of a graph with minimum length.
B
3 1
2
1 C 2
A E
1
1 3
D
Imagine each vertex represents a city and the weight on each edge represents the
operating cost of providing flight between the two cities.
Problem: An airline company intends to minimize operating cost and yet provide
connected flight routes between any two cities. Is there way to do this?
B
3 1
2
1 C 2
A E
1
1 3
D
GEH1036: CHAPTER 2 GRAPHING 5
Is there an efficient way to solve this problem if the connection of cities looks like
the one above?
(a) the sequence alternates between vertices and edges, starting and ending with
vertices; and
(b) each edge in the sequence joins the vertices that occur immediately before and
after it in the sequence.
A walk that starts and ends at different vertices is called an open walk.
A walk that starts and ends at the same vertex is called a closed walk.
A walk that contains no repeated vertices and edges is called a path.
Example 2.4.
B
A C
E D
GEH1036: CHAPTER 2 GRAPHING 6
(i) (A, AB, B, BC, C, CE, E, EB, B, BD, D) is a walk in this graph starting from
A and ending at D. We refer to this walk as a walk from A to D. Notice
that this walk visits the vertex B twice. Since there are no multiple edges, we
can describe this walk more efficiently by leaving out the edges and just write
(A, B, C, E, B, D) or simply ABCEBD.
(iii) The walk AEBD is a path since it has no repetitions of vertices or edges.
Definition 2.5. A cycle in a graph is a closed walk in which the only repetition is
the first and the last vertex.
The length of a walk is defined as the number of edges in the walk, including repe-
titions.
Example 2.6.
B
A C
E D
Example 2.7. Find all the cycles of length 5 in the following graph:
v1
v6
v5 v10 v7 v2
v9 v8
v4 v3
outer vertices if 1 i 5;
type 3: exactly three of the vertices of this cycle are outer vertices;
type 4: exactly three of the vertices of this cycle are inner vertices.
v1 v2 v3 v8 v6 v1 , v2 v3 v4 v9 v7 v2 ,
v3 v4 v5 v10 v8 v3 , v4 v5 v1 v6 v9 v4 ,
v5 v1 v2 v7 v10 v5 .
v1 v2 v7 v9 v6 v1 , v2 v3 v8 v10 v7 v2 ,
GEH1036: CHAPTER 2 GRAPHING 8
v3 v4 v9 v6 v8 v3 , v4 v5 v10 v7 v9 v4 ,
v5 v1 v6 v8 v10 v5 .
Example 2.8. Consider the simple graph with five vertices such that any two of the
vertices are joined by an edge.
Solution.
(a) We can list all the edges. Denote the vertices by A, B, C, D and E. The
5
number of edges is 2 :
AB, AC, AD, AE, BC, BD, BE, CD, CE, DE.
5
There are 2
edges in total.
Definition 2.9 (Degree). The degree of a vertex in a graph is the number of edges
that occur at that vertex, with every loop counted as two.
Example 2.10.
B
A C
E D
Theorem 2.11 (The Degree Theorem). In any graph, the sum of all the degrees is
equal to twice the number of edges.
In particular, the sum of all the degrees must be even.
Proof. Every edge contributes twice to the sum of all the degrees.
For example, in the graph below
B
__
__
__
__
A C
E ? ? ? ???
D
Example 2.12. Suppose a simple graph has 100 vertices and every vertex has degree
5.
How many edges does this graph contain?
Therefore,
5 100
no. of edges = = 250.
2
There are 250 edges in this graph.
Example 2.14. Is it possible to find a graph with exactly one odd vertex?
Solution. No.
Suppose v1 , v2 , . . ., vn are all the vertices of a graph G. Without loss of generality,
assume that v1 is the only odd vertex in G, that is
Definition 2.15. In any graph G, the symbol (G) represents the minimum degree
in G; the symbol 4(G) represents the maximum degree.
Example 2.16. Suppose you know that a certain graph G must contain seven ver-
tices and that (G) = 3 and 4(G) = 5.
Show that G must have at least 12 edges.
Solution. Let e(G) denote the number of edges in G, and v1 , . . ., v7 denote all the
seven vertices in G.
By the Degree Theorem,
Since the minimum degree is 3, we must have d(vi ) 3 for all i = 1, . . . , 7. Since
the maximum degree is 5, there exists at least one vertex of degree 5, say d(v7 ) = 5.
GEH1036: CHAPTER 2 GRAPHING 11
Therefore,
23 = 3| + {z
+ 3} +5 d(v1 ) + + d(v7 ) = 2 e(G).
6 times
We deduce that
23
e(G) = 11.5.
2
Since e(G) must be a positive integer, we conclude that
e(G) 12,
that is G must have at least 12 edges.
Example 2.17. Explain why there cannot exist a graph with 11 vertices such that
every vertex has degree 3.
Solution. If there is such a graph, then the sum of all the degrees would be
3 11 = 33 which is odd, contradicting the Degree Theorem.
Example 2.18. Find a simple graph with 7 vertices such that exactly two vertices
have degree 3, exactly three vertices have degree 2 and exactly two vertices have
degree 1.
Solution. Exercise.
Example 2.19. Explain why there cannot be a simple graph with 6 vertices such
that exactly four vertices have degree 5 and exactly two vertices have degree 2.
c d f
a b e
a must be joined to b, c, d, e, f .
Then each of a, b, c, d must be joined by an edge to all other vertices. This means
the degrees of e and f must be at least 4, a contradiction.
Example 2.20. Let P be a longest path in a simple graph G, and let represent
the length of P .
Show that both the starting point and the ending point of P must have degree less
than or equal to .
GEH1036: CHAPTER 2 GRAPHING 12
Solution. Suppose u is the starting point of P . Since P has length , P must have
exactly + 1 vertices.
If u is joined to a vertex that does not belong to P , then we get a path that is longer
than P .
Thus u can only be joined to vertices in P and thus its degree must be .
u
P
2.3 Trees
Definition 2.21 (Trees). A tree is a simple graph that is connected and contains
no cycle.
a tree
a tree
not a tree
GEH1036: CHAPTER 2 GRAPHING 13
not a tree
not a tree
Definition 2.22. A leaf (plural: leaves) is a vertex of degree 1.
Observe that a tree with two or more vertices will always have a leaf. In fact, it
always has at least two leaves.
Theorem 2.23 (Leaf Lemma). Every tree with two or more vertices has at least
two vertices of degree 1.
u
P
The vertex u can only be joined to vertices in P . If any of the curved edges is
present, a cycle would be created.
The endpoints must have degree 1! Otherwise, since the endpoint is already at the
end of a longest path, it can only be joined to other vertices on the path. If it is
joined a vertex other than its immediate neighbour in the path, a cycle would be
created, which is impossible.
Theorem 2.24 (Tree Theorem). Every tree with n vertices has exactly n 1 edges.
Proof. This is obviously true if the tree has only one vertex. So lets assume that
the tree has two or more vertices.
By the Leaf Lemma, we can always find a vertex of degree 1. Delete this vertex from
the tree together with the unique edge joined to it. The resulting graph is again a
tree.
GEH1036: CHAPTER 2 GRAPHING 14
Repeat this deletion process for the resulting tree until we are left with just one
single vertex without any edge.
Think about the number of vertices and the number edges that we have deleted.
These numbers must be the same, namely n 1, because we deleted exactly one
vertex and one edge at each step of our deletion process.
Since we have exactly one single vertex left without edges in the end, we deduce
that the number of vertices of the original tree is exactly one more than the number
of edges it contains.
Solution.
Solution. Suppose the tree contains n vertices. By the Tree Theorem, it has n 1
edges.
By the Degree Theorem,
4 + 3 3 + (n 4) = 2 (n 1),
GEH1036: CHAPTER 2 GRAPHING 15
9 + n = 2n 2,
n = 11.
Hence, there are 11 vertices in this tree.
Example 2.27. Draw a tree with the properties given in the preceding example.
Solution. Exercise.
A 2 B 3C
2
3 1
D
The weight of the graph G is
w(G) = 2 + 3 + 2 + 3 + 1 = 11.
Some examples of subgraphs of the graph G above and their corresponding weights
are given below:
GEH1036: CHAPTER 2 GRAPHING 16
H1 :
A 2 B 3C
3 1
D
w(H1 ) = 2 + 3 + 3 + 1 = 9.
H2 :
A 2 B 3C
w(H2 ) = 2 + 3 = 5.
H3 :
A 2 B 3C
2
D
w(H3 ) = 2 + 3 + 2 = 7.
All the spanning trees (and their respective weights) of the graph G above are listed
below:
T1 :
A 2 B 3C
2
D
w(T1 ) = 2 + 3 + 2 = 7.
T2 :
A 2 B 3C
1
D
w(T2 ) = 2 + 3 + 1 = 6.
GEH1036: CHAPTER 2 GRAPHING 17
T3 :
A 2 B C
2
1
D
w(T3 ) = 2 + 2 + 1 = 5.
T4 :
A 2 B 3C
3
D
w(T4 ) = 2 + 3 + 3 = 8.
T5 :
A 2 B C
3 1
D
w(T5 ) = 2 + 3 + 1 = 6.
T6 :
A B 3C
2
3
D
w(T6 ) = 3 + 2 + 3 = 8.
T7 :
A B C
2
3 1
D
w(T7 ) = 3 + 2 + 1 = 6.
T8 :
A B 3C
3 1
D
w(T8 ) = 3 + 1 + 3 = 7.
GEH1036: CHAPTER 2 GRAPHING 18
In the above example, there is only one minimal spanning tree, namely T3 , whose
weight is 5.
Why minimal spanning trees?
Vertices are houses in some neighboorhood; and edges are TV cable joining
these house.
Edge weights correspond to the costs to bury the cable between two houses.
A minimum spanning tree would be a subgraph joining all houses with the
lowest total cost.
(1) Start with any vertex and select an edge having minimum weight among all
edges at that vertex.
(2) Consider ALL edges that go from each vertex already reached to a new vertex.
Select one that has minimum weight.
Example 2.34. Apply Prims Algorithm to this graph starting from the vertex A:
3 1
2
1 2
A C E
1 3
0
(1) Starting from A, we find that the edges of minimum weight at that vertex are
AC and AD. The algorithm allows us to choose either one.
GEH1036: CHAPTER 2 GRAPHING 19
1
A C
D
(2) Suppose we selected AC:
3 1
2
1 2
A C E
1 3
0
D
We box the vertices that have been reached to distinguish them from the rest. We
also use double lines to indicate the edges we have selected.
(3) The edges that join a vertex that has been reached to a new vertex are
3
2
1 2
A C E
1
0
D
(4) We must select the edge CD:
3 1
2
1 2
A C E
1 3
0
(5) We now have {A, C, D} as the set of reached vertices. Consider edges that go
from one of these reached vertices to a new (unreached) vertex:
Among these edges, the ones that have minimum weight are
BC, CE.
Both choices are allowed by the algorithm. We can choose one of them, say BC:
GEH1036: CHAPTER 2 GRAPHING 21
3 1
2
1 2
A C E
1 3
0
(6) We now have {A, C, D, B} as the set of reached vertices. Consider edges
that go from one of these reached vertices to a new (unreached) vertex that do not
produce cycle:
BE.
Selecting this edges produces a minimal spanning tree that we are looking for:
3 1
2
1 2
A C E
1 3
0
Example 2.35. Apply Prims Algorithm to the following graph starting from the
vertex C.
2
B C
0 5
3
A 2 4 F
5
1
4
D E
Solution. Exercise.
a loop multiple edges
(a) the sequence alternates between vertices and directed edges, starting and ending
with vertices; and
GEH1036: CHAPTER 2 GRAPHING 23
(b) each directed edge in the sequence joins the vertices that occur immediately
before and after it in the sequence in the direction indicated by the arrow of
the directed edge.
_ _
D 2,
C
A B C A.
A B C A D C.
(c) NOT a walk because the edge connecting C and D is not pointing from C to
D:
A B C D,
A B D.
Around the 1700s, citizens of Konigsburg, Prussia (which is now Kaliningrad, Rus-
sia) would try to walk around the city, crossing each of the citys seven bridges
exactly once.
Below is a map of the city showing the bridges over the Pregel River. There is also
a simplified schematic of the city. Is there a route that they can take to accomplish
this goal? You may start in any region you wish.
GEH1036: CHAPTER 2 GRAPHING 24
Definition 2.39 (Euler walk). An Euler walk in a graph is a walk that uses every
edge in the graph exactly once.
Therefore, a closed Euler walk (also known as Euler circuit) is an Euler walk
that starts and ends at the same vertex.
An open Euler walk is an Euler walk that starts and ends at different vertices.
Our definition of Euler walk applies to both undirected and directed graphs with
or without loops or multiple edges.
Example 2.40. In the graph below, see if you can find an open or closed Euler walk.
A
B
C D
E
GEH1036: CHAPTER 2 GRAPHING 25
A B C
F G
E D
2,
A Zd B
_ _
D 2,
C
Leonhard Euler
Born: 15 April 1707, Basel, Switzerland
Died: 18 September 1783 (aged 76), Saint Petersburg, Russian Empire
Theorem 2.41 (Euler Walk Theorem I). A connected (undirected) graph contains
a closed Euler walk (Euler circuit) if and only if every vertex has even degree.
A B
/ / /
A B
/ / / / / / / / / /
A B C X D A.
If this closed walk already covers all the edges, we are done.
If not, since the graph is connected, there is an unused edge connected to some
vertex, say X, on the walk.
We can now start from X, move along the unused edge and construct another closed
walk.
X Y X.
GEH1036: CHAPTER 2 GRAPHING 27
A B C X D A.
X Y X.
A B C X Y X D A.
Theorem 2.42 (Euler Walk Theorem II). A connected (undirected) graph contains
an open Euler walk starting from vertex A and ending at vertex B if and only if
A C X D B.
We can now start from X, move along the unused edge and construct another closed
walk.
X Y X.
A C X Y X D B.
By a similar argument, we have the following directed version of Euler Walk Theo-
rem.
(a) for vertex A, the number of arrows pointing out is exactly one more than the
number of arrows pointing in;
(b) for vertex B, the number of arrows pointing in is exactly one more than the
number of arrows pointing out;
(b) for all the other vertices, the number of arrows pointing in is equal to the
number of arrows pointing out.
Example 2.45. Does the following graph have a closed Euler walk? Explain your
answer.
A B C D
Example 2.46. Does the following graph have an open Euler walk? Explain your
answer.
GEH1036: CHAPTER 2 GRAPHING 29
A B
E D
Solution. No. Because it has more than two vertices of odd degree.
Example 2.47. Does the following directed graph have a closed Euler walk? Explain
your answer.
C ]f
9
x 2, B
ALR _LR
_
&
E lr D
Solution. No. Because the number of arrows pointing into B (there are exactly 2
such arrows) is not equal to the number of arrows pointing out of B (there is exactly
1 such arrow).
Example 2.48. Does the following directed graph have an open Euler walk? Explain
your answer.
9 LR
8A _E
,2 B ,2
& +%2,
A _LR 9 8A C D
& ,
F sy
Solution. No. Because, for example, at vertex A, the difference between the
number of arrows going out and that of going in is more than one.
GEH1036: CHAPTER 2 GRAPHING 30
Example 2.49. Add the smallest possible number of edges to the following graph in
order to produce a graph that contains an open Euler walk.
A B C
A B C
E
An open Euler walk is:
A D C E A B D E B C.
GEH1036: CHAPTER 2 GRAPHING 31
(1) Make sure the graph is connected and all vertices are even.
(4) If not construct another closed walk and combined the two to get a bigger
closed walk.
A
B
H
C J
I
G D K
F E
A
B
H
C J
I
G D K
F E
A
B
H
C J
I
G D K
F E
A
B
H
C J
I
G D K
F E
AEBF A
AEBF A
to get
ABCJ KDEF GI
HAEBF A
A
B
H
C J
I
G D K
F E
HCDGH
ABCJ KDEF GI
HAEBF A
and
HCDGH
to get
ABCJ KDEF GI
HCDGHAEBF A
A D
C
GEH1036: CHAPTER 2 GRAPHING 34
A B
H C
I J K
G D
F E
Problem: Find a trail that uses all the edges of a graph with minimum length.
Given a connected weighted graph or directed graph G, find the shortest circuit
(closed walk with smallest weight) that uses each edge in G at least once.
However, in general there are vertices of odd degree. How do we deal with them?
GEH1036: CHAPTER 2 GRAPHING 35
If there are two odd vertices A and B, then there is only one way of pairing them
together:
{AB}
If there are four odd vertices A, B, C, D, then there are three ways of pairing them
together:
{AB, CD}, {AC, BD}, {AD, BC}.
Step 3: For each pairing, find paths that connect the vertices with the mini-
mum weight. Find the pairings such that the sum of the weights is minimised.
Step 4: On the original graph add the edges that have been found in Step
3.
Step 5: The length of an optimal Chinese postman route is the sum of all
the edges added to the total found in Step 4.
Example 2.53. Solve the Chinese Postman Problem for the following graph (units
given in meters (m)):
Solution.
Step 1: The odd vertices are A and H.
Step 2: There is only one way of pairing these odd vertices, namely AH.
Step 3: The shortest way of joining A to H is using the path AB, BF , F H, a
total length of 160.
Step 4: Draw these edges onto the original network.
Step 5: The length of the optimal Chinese postman route is the sum of all the
edges in the original network, which is 840 m, plus the answer found in Step 4, which
is 160 m. Hence the length of the optimal Chinese postman route is 1000 m.
Step 6: One possible route corresponding to this length is ADCGHCABDF BEF HF BA,
but many other possible routes of the same minimum length can be found.
GEH1036: CHAPTER 2 GRAPHING 37
Example 2.54. A county council is responsible for maintaining the following net-
work of roads. The number on each edge is the length of the road in miles.
(a) A council worker has to inspect all the roads, starting and finishing at A. Find
the length of an optimal Chinese postman route.
(b) A supervisor, based at A, also wishes to inspect all the roads. However, the
supervisor lives at H and wishes to start his route at A and finish at H. Find
the length of an optimal Chinese postman route for the supervisor.
3 4
1 2 1
4 3
Example 2.57. The following is NOT a proper vertex coloring because there is an
edge whose endpoints receive the same colors.
3 2
1 2 1
2 3
We are interested in a proper vertex coloring of a given graph G using the smallest
possible number of colors.
The number of colors that occurs in a minimal proper vertex coloring is called the
chromatic number of G, denoted by
(G).
Example 2.58. Find a minimal proper vertex coloring of the following graph. What
is the chromatic number of this graph.
GEH1036: CHAPTER 2 GRAPHING 39
Definition 2.59. The complete graph on n vertices is a graph on n vertices such
that any two vertices are joined by an edge. It is denoted by Kn .
Example 2.62. Find a minimal proper vertex coloring for the graph G below, and
determine its chromatic number:
Solution.
1 3
2 3 2 1
1 3
GEH1036: CHAPTER 2 GRAPHING 40
The above is a proper coloring using 3 colors. So the chromatic number is at most
3:
(G) 3.
The graph contains a complete graph K3 . By the Vertex Coloring Theorem 1, the
chormatic number is at least 3:
(G) 3.
Example 2.63. Find a minimal proper vertex coloring for the graph G below, and
determine its chromatic number:
Example 2.64. Find a minimal proper vertex coloring for the graph G below, and
determine its chromatic number:
Example 2.65. Find a graph whose chromatic number is 3 but it does not contain
any triangle.
Solution.
GEH1036: CHAPTER 2 GRAPHING 41
Definition 2.67. A cycle graph of length n is denoted by Cn . For example, the
preceding example is C7 .
Theorem 2.68 (Vertex Coloring Theorem 2). If a graph G contains a cycle graph
Cn on n vertices where n is odd, then a proper vertex coloring of G must use at least
3 colors. Therefore, (G) 3.
Example 2.69. Find a minimal proper vertex coloring for the graph G below, and
determine its chromatic number:
2 3
1 1 2 2
3 2 1 3
Example 2.70. Construct a graph whose chromatic number is 4 but it does not
contain a complete graph K4 .
GEH1036: CHAPTER 2 GRAPHING 42
Solution.
d1 d2 d3
(2) Place the integers 1, 2, 3, . . . directly under these degrees until you reach an
integer k such that k + 1 > dk+1 :
d1 d2 d3 dk dk+1
1 2 3 k STOP
(G) k + 1.
Example 2.72. Apply the Upper bound algorithm to the following graph:
5 5 4 4 3 3 3 3 3 3
1 2 3 4 STOP
(G) 5.
(1) If every vertex in a graph has degree at most k, then we need at most k + 1
colors in a minimal proper coloring.
(2) The upper bound algorithm instructs us to color the vertices one by one in
decreasing order of their degrees, using a new color at each step (though it is
not optimal to do so).
When the algorithm stops (i.e. when k + 1 > dk+1 ), we have already used k
colors and all the remaining vertices now have degree at most k. By (1), no
new colors (i.e. colors beyond k + 1) are ever needed to color these remaining
vertices.
Example 2.73. Apply the Upper bound algorithm to the following graph G:
5, 4, 4, 4, 3, 3, 3, 3, 3.
3 2
1 1
1
2 3
3 2
So (G) 3.
Since the graph has a triangle, (G) 3.
Hence,
(G) = 3.
C1 C2 , C7 , C6 , C12
C2 C1 , C3 , C7 , C8
C3 C2 , C4 , C8 , C9
C4 C3 , C5 , C9 , C10
C5 C4 , C6 , C10 , C11
C6 C1 , C5 , C11 , C12
C7 C1 , C2 , C13
GEH1036: CHAPTER 2 GRAPHING 45
C8 C2 , C3 , C13
C9 C3 , C4 , C13
C10 C4 , C5 , C13
C11 C5 , C6 , C13
C12 C1 , C6 , C13
C2 C3
C8
C7 C9
C1 C13 C4
C12 C10
C11
C6 C5
2 3
1
1 1
3 2 2
1 1
1
2 3
The minimum number of warehouses the factory needs in order to store its chemicals
safely is 3.