Anda di halaman 1dari 46

GEH1036: Chapter 2 Graphing

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

AB can also be written as BA.

Can also draw it like this:

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:

(1) Social network analysis:

Facebook has over 500 million active members

If Facebook was a country, it would be the fourth most populated on earth

translated into over 100 languages

More than half of everyone who shops online has a Facebook profile.

Facebook as a graph:
GEH1036: CHAPTER 2 GRAPHING 3

Vertices = people

Edges = some kind of social or person-to-person relationship

Facebook is popular for advertising and marketing.


Thanks to newsfeed!
Some people are just more active and influential than others
Problem: How do we decide if someone is more influential than the other?

(2) Storing chemicals:


In the following graph, an edge between Ci and Cj indicates that the chemical Ci
and Cj must be stored in different warehouse, whereas a lack of an edge indicates
that it is safe to store the respective chemicals in the same warehouse.

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?

(3) Chinese Postman Problem:


A postman has to start at A, walk along all 13 streets and return to A. The numbers
on each edge represent the length, in metres, of each street.
GEH1036: CHAPTER 2 GRAPHING 4

Problem: Find a trail that uses all the edges of a graph with minimum length.

(4) Shortest path:

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?

2.2 Basic Terminology


Definition 2.3 (Walk). A walk is a sequence of vertices and edges in a graph such
that

(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.

(ii) Another walk is ABCBEA where we have repetitions of vertices as well as


edges. Moreover, it is a closed walk since it starts and ends at the same vertex.

(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

(i) Three cycles of length 4:


ABCEA, ABDEA and BCEDB.

(ii) Why is there no cycle of length 5?


Suppose there is such a cycle. Then it must contain all the vertices, in par-
ticular, it contains C and D. So it contains the edges BC, CE, BD and DE.
Since these four edges already form a cycle of length 4, they cannot be part
of a cycle of length 5. This is a contradiction. Hence, there are no cycles of
length 5 in this graph.
GEH1036: CHAPTER 2 GRAPHING 7

Example 2.7. Find all the cycles of length 5 in the following graph:
v1

v6

v5 v10 v7 v2

v9 v8

v4 v3

Solution. Call the vertices vi

outer vertices if 1 i 5;

inner vertices if 6 i 10.

Any cycle of length 5 is of one of the following types:

type 1: all vertices of this cycle are outer vertices;

type 2: all vertices of this cycle are inner vertices;

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.

There is only one cycle of type 1, namely v1 v2 v3 v4 v5 v1 .


There is only one cycle of type 2, namely v6 v8 v10 v7 v9 v6 .
There are 5 cycles of type 3, namely

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 .

There are 5 cycles of type 4, namely

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 .

Hence, there are only 12 cycles of length 5 in total.

Example 2.8. Consider the simple graph with five vertices such that any two of the
vertices are joined by an edge.

(a) How many edges are there in this graph?

(b) How many cycles of length 3 are there in this graph?

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.

(b) The cycles are


ABCA, ABDA, ABEA,
ACDA, ACEA,
ADEA,
BCDB, BCEB,
BDEB,
CDEC.
5

There are 3
cycles of length 3 in total.
Note: Every set of 3 vertices corresponds to one cycle of length 3.

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.

The notation d(v) represents the degree of vertex v.


GEH1036: CHAPTER 2 GRAPHING 9

Example 2.10.
B

A C

E D

d(A) = 2, d(B) = 4, d(C) = 2, d(D) = 2, d(E) = 4.

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

The edge AB contributes 1 to each of the the degree of A and B.

The edge DE contributes 1 to each of the the degree of D and E.

Example 2.12. Suppose a simple graph has 100 vertices and every vertex has degree
5.
How many edges does this graph contain?

Solution. By the Degree Theorem,

5| + 5 +{z + 5} = 2 no. of edges.


100 times
GEH1036: CHAPTER 2 GRAPHING 10

Therefore,
5 100
no. of edges = = 250.
2
There are 250 edges in this graph.

Definition 2.13. An odd vertex is a vertex whose degree is an odd number.


An even vertex is a vertex whose degree is an even number.

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

d(v1 ) is an odd number

d(v2 ), . . ., d(vn ) are even numbers.

By the Degree Theorem,

d(v1 ) + d(v2 ) + + d(vn )

is an even number since it is twice the number of edges.


This is not possible since d(v1 ) is odd and d(v2 ) + + d(vn ) is even.

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,

d(v1 ) + + d(v7 ) = 2 e(G).

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.

Solution. Suppose there is such a graph G.


Let a, b, c, d, e, f be the vertices with the first 4 having degree 5 and the last 2 having
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

u can only be joined to vertices in 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.

Proof. Consider a longest path P in the tree.


What must be true about its endpoints?

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.

Example 2.25. List all the trees with 5 unlabeled vertices.

Solution.

Example 2.26. Suppose a tree has the following properties:

(i) exactly one vertex of degree 4; and

(ii) exactly three vertices of degree 3; and

(iii) all the remaining vertices have degree 1.

How many vertices are there in this tree?

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.

2.4 Minimal spanning trees


Definition 2.28 (Weighted graphs). A weighted graph is a graph in which each
edge has a number associated with it, which we refer to as the weight of that edge.

In applications, these weights represent cost or travel time etc.


In many, if not most, situations where weighted graphs are applied, it is the sum
of the weights of the edges of some subgraphs which is important.
Definition 2.29 (Subgraph). A subgraph of a graph G is a graph H whose vertices
and edges are taken from those of G.
Definition 2.30 (Weight of a graph). The weight of a graph G is the sum of
weights of all its edges. Symbolically,
X
w(G) = w(e)
e edge of G

where w(e) denotes the weight of the edge e.


Example 2.31. Consider the following weighted graph G:

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.

Definition 2.32 (Spanning tree). A spanning tree of a given graph G is a subgraph


T of G which is a tree and it contains ALL the vertices of G.

Definition 2.33 (Minimal spanning tree). A minimal spanning tree of G is a


spanning tree which has the minimum weight among all the spanning trees of G.

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.

Prims algorithm: A procedure for constructing a minimal spanning tree in a


given weighted graph:
Input: a weighted graph G
Output: a minimal spanning tree T of G
Algorithm:

(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.

(3) Continue until all vertices have been reached.

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

AB, AD, BC, CD, CE.

The one(s) with minimum weight is CD.


GEH1036: CHAPTER 2 GRAPHING 20

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:

AB, BC, CE, DE.

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, CE, DE.

Among these edges, the one that have minimum weight is

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

The weight of this minimal spanning tree is 1 + 0 + 2 + 1 = 4.


Exercise: Apply Prims algorithm to the same graph starting with vertex B.
(The minimum spanning trees that you get starting from different vertices may be
different, but their wieghts are all the same.)
GEH1036: CHAPTER 2 GRAPHING 22

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.

2.5 Euler walks


In this section, we allow graphs to contain loops and multiple edges:


a loop multiple edges

We will also consider directed graphs.

Definition 2.36 (Directed graph). A directed graph is a graph in which every


edge is assigned a direction indicated by an arrow (called a directed edge).

Definition 2.37 (Walk in directed graph). A walk in a directed graph is a sequence


of vertices and directed edges such that

(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.

Example 2.38. Consider the following directed graph:


 2,
A Zd B


_  _
D  2, 
C

(a) A a closed walk:

A, AB, B, BC, C, CA.

When there is no confusion, we can simply write:

A B C A.

(b) An open walk:

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,

(d) NOT a walk because there is no edge connecting B to 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.

Notice that when tracing an Euler walk in a graph:

(i) a vertex may be visited more than once;


(ii) every edge is visited exactly once;
(iii) we are tracing the entire graph without lifting our pen.

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

Old Swiss 10 Franc banknote honoring Euler

1957 Soviet Union stamp commemorating the 250th birthday of Euler.


GEH1036: CHAPTER 2 GRAPHING 26

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.

Proof. (Forward implication) Consider tracing a closed Euler walk.


Since we must use different edges when we go in and out of a vertex, these two edges
can be put in a pair.

A B
/ / /



Different edges are used to enter and exit B.


Since the edges can be put into pairs, the number of edges joined to the vertex must
be even, i.e. the vertex has even degree.
(Backward implication) We try to construct an Euler walk. Choose a vertex A and
go to another vertex, say B.

A B
/ / / / / / / / / /

At B, the number of edges available is odd, i.e., is 1.


Thus we can move from B to another vertex.
This is always the case when we are not at A.
Since the number of edges is finite, we have to return to A.
Hence we have a closed walk.

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.

We now combine the two walks into a bigger walk.

A B C X Y X D A.

Continuing this way, well end up with an Euler walk.

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) vertex A and B have odd degree; and

(b) all the other vertices have even degree.

Proof. (Forward implication)


Consider tracing an open Euler walk the starts from A and ends at vertex B.
Since we do not end at vertex A, the number of times we left A must be exactly one
more than the number of times we visited A. So A must have odd degree. Similarly,
the number of times we visited B must be exactly one more than the number of
times we left B; so B also has odd degree.
For any of the other vertex, the number of times we visited and left the vertex are
exactly the same. Therefore, it must have even degree.
(Backward implication)
As in the previous case, construct an Euler walk from A. Now the walk will end in
B as the walk can continue if it is not at B.

A C X D B.

If this 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.
Now all vertices are of even degree.
GEH1036: CHAPTER 2 GRAPHING 28

We can now start from X, move along the unused edge and construct another closed
walk.

X Y X.

The two walks can be combined to yield a bigger walk.

A C X Y X D B.

By a similar argument, we have the following directed version of Euler Walk Theo-
rem.

Theorem 2.43 (Euler Walk Theorem I directed version). A connected directed


graph contains a closed Euler walk (Euler circuit) if and only if for every vertex the
number of arrows pointing in is equal to the number of arrows pointing out.

Theorem 2.44 (Euler Walk Theorem II directed version). A connected directed


graph contains an open Euler walk starting from vertex A and ending at vertex B if
and only if

(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

Solution. No. Because it contains vertices of odd degree.

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

Solution. Add the edge {D, E}:

A B C

E
An open Euler walk is:

A D C E A B D E B C.
GEH1036: CHAPTER 2 GRAPHING 31

An algorithm to construct an Euler circuit.

(1) Make sure the graph is connected and all vertices are even.

(2) Start anywhere. Construct a closed walk.

(3) If the closed walk covers all edges, then done.

(4) If not construct another closed walk and combined the two to get a bigger
closed walk.

(5) Repeat 4 and stop when all edges are used.

Example 2.50. Find an Euler circuit if it exists.

A
B

H
C J
I

G D K

F E

1. Check graph is connected and all vertices are even.


2. Construct a closed walk.

A
B

H
C J
I

G D K

F E

ABCJ KDEF GIHA


GEH1036: CHAPTER 2 GRAPHING 32

A
B

H
C J
I

G D K

F E

Whats left after the closed walk is removed.


3. Construct the closed walk

A
B

H
C J
I

G D K

F E

AEBF A

4. Combine two two closed walks

ABCJ KDEF GIHA

AEBF A

to get
ABCJ KDEF GI
HAEBF A

5. Construct a closed walk


GEH1036: CHAPTER 2 GRAPHING 33

A
B

H
C J
I

G D K

F E

HCDGH

6. Combine the closed walks

ABCJ KDEF GI
HAEBF A
and

HCDGH

to get

ABCJ KDEF GI
HCDGHAEBF A

Example 2.51. Find an Euler circuit if it exists.

A D

C
GEH1036: CHAPTER 2 GRAPHING 34

Example 2.52. Find an Euler circuit if it exists.

A B

H C
I J K
G D

F E

Lets consider the following problem.


A postman has to start at A, walk along all 13 streets and return to A. The numbers
on each edge represent the length, in metres, of each street.

Problem: Find a trail that uses all the edges of a graph with minimum length.

Chinese Postman Problem:

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.

The simplest case:


This occurs when every vertex in the graph has even degree, for in this case an Euler
circuit solves the problem. Any Euler circuit will have the minimum total weight
since no edges are retraced in an Euler circuit.

However, in general there are vertices of odd degree. How do we deal with them?
GEH1036: CHAPTER 2 GRAPHING 35

Pairing of odd vertices:


By the Degree Theorem, there are always even number of odd vertices in a graph.

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}.

Number of odd vertices Number of possible pairings


2 1
4 31
6 531
..
.
2k (2k 1) (2k 3) 5 3 1

Step 1: List all odd vertices.

Step 2: List all possible pairings of odd vertices.

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.

Step 6: A route corresponding to this minimum weight is an Euler circuit


in the graph obtained in Step 5.
GEH1036: CHAPTER 2 GRAPHING 36

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.

The council office is based at A.

(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.

2.6 Vertex Coloring


Definition 2.55. A proper vertex coloring of a graph is an assignment of a
color (usually represented by a number) to each vertex of the graph in such a way
that any two vertices that are adjacent have different colours.

Example 2.56. An example of a proper vertex coloring:


GEH1036: CHAPTER 2 GRAPHING 38

3 4

1 2 1

4 3

There are 4 different colors used in the above coloring.

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.

Such a coloring is called a minimal proper vertex coloring of G.

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.60. What is the chromatic number of K4 ?

What is the chromatic number of K5 ?

What is the chromatic number of Kn ?

Theorem 2.61 (Vertex Coloring Theorem 1). If a graph G contains a complete


graph on n vertices, then a proper vertex coloring of G must use at least n colors.
Therefore, (G) n.

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.

We deduce that the above is a minimal proper coloring and


(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

Example 2.66. What is the chromatic number of the following graph?


Definition 2.67. A cycle graph of length n is denoted by Cn . For example, the
preceding example is C7 .

What is the chromatic number of the cycle graph Cn when n is odd?


What is the chromatic number of the cycle graph Cn when n is even?

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:

Solution. The graph contains a cycle of length 5. So we need at least 3 colors.


But 3 colors are enough for a proper coloring, as given below:

2 3

1 1 2 2

3 2 1 3

So the chromatic number of this graph is 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.

Theorem 2.71 (Upper bound algorithm for ).

(1) Arrange the degrees of a graph G in decreasing order:

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

Then for this graph G, we have

(G) k + 1.

Example 2.72. Apply the Upper bound algorithm to the following graph:

Solution. The degree sequence in decreasing order is


GEH1036: CHAPTER 2 GRAPHING 43

5 5 4 4 3 3 3 3 3 3
1 2 3 4 STOP

Conclusion: the chromatic number of this graph is

(G) 5.

Why the algorithm works

(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:

Solution. The degree sequence in decreasing order is

5, 4, 4, 4, 3, 3, 3, 3, 3.

The upper bound algorithm gives:


5 4 4 4 3 3 3 3 3
1 2 3 4 STOP
Conclusion: (G) 5.
GEH1036: CHAPTER 2 GRAPHING 44

Actually, we can use less than 5 colors.

3 2

1 1
1
2 3

3 2

So (G) 3.
Since the graph has a triangle, (G) 3.
Hence,
(G) = 3.

Example 2.74. A particular chemical factory produces 13 different kinds of chem-


icals, labeled as C1 , C2 , . . ., C13 . The following table shows that it is not safe to
store the chemical in the first column with those on the second column in the same
row; otherwise, it is safe to store them together in the same warehouse.
What is the minimum number of warehouses the factory needs in order to store its
chemicals safely?

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

C13 C7 , C8 , C9 , C10 , C11 , C12

Solution. We construct a graph with the 13 chemicals as vertices as follows: join


an edge between Ci and Cj if Ci and Cj appear in the same row in the table above,
i.e. it is not safe to store Ci and Cj i the same warehouse.
Let colors represent the warehouses. Then we must put different colors to adjacent
vertices. The minimum number of warehouses needed is just the chromatic number
of the graph:

C2 C3
C8
C7 C9

C1 C13 C4

C12 C10
C11
C6 C5

The graph contains a triangle, so at least 3 colors are needed.


As the following coloring shows, 3 colors are sufficient:
GEH1036: CHAPTER 2 GRAPHING 46

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.

Anda mungkin juga menyukai