Chapter10 5
Chapter10 5
5
Euler and Hamiltonian
Graphs
Section Summary
Euler Paths and Circuits
Hamilton Paths and Circuits
Applications of Euler & Hamilton
Circuits
Euler Paths and
Circuits Leonard Euler
(1707-1783)
• The town of Kӧnigsberg, Prussia (now Kalingrad,
Russia) was divided into four sections by the branches
of the Pregel river. In the 18th century seven bridges
connected these regions.
• People wondered whether it was possible to follow a
path that crosses each bridge exactly once and
returns to the starting point.
Fig2. Multigraph
Model of the
Bridges of
Fig1. The 7 Bridges of Kӧnigsberg
Kӧnigsberg
Euler Paths and Circuits
(continued)
Definition: An Euler circuit in a graph G
is a simple circuit containing every edge
of G. An Euler path in G is a simple path
containing every edge of G.
Euler Paths and Circuits
(continued)
Example: Which of the undirected graphs G1, G2,
and G3 has a Euler circuit? Of those that do not,
which has
d
an Euler path? d
d c
e c e c
a b
a a b
b
G1 G2 G3
Solution: The graph G1 has an Euler circuit.
But, neither G2 nor G3 has an Euler circuit.
Note that G3 has an Euler path.
But, there is no Euler path in G2.
Necessary Conditions for
Euler Circuits and Paths
An Euler circuit begins with a vertex a and
continues with an edge incident with a, say {a,
b}. The edge {a, b} contributes one to deg(a).
Each time the circuit passes through a vertex
it contributes two to the vertex’s degree.
Finally, the circuit terminates where it started,
contributing one to deg(a).
Therefore deg(a) must be even.
We conclude that the degree of every
other vertex must also be even.
Necessary Conditions for
Euler Circuits and Paths
By the same reasoning, we see that the initial
vertex and the final vertex of an Euler path have
odd degree, while every other vertex has even
degree. So, a graph with an Euler path has
exactly two vertices of odd degree.
In the next slide we will show that these
necessary conditions are also sufficient
conditions.
Sufficient Conditions for Euler
Circuits and Paths
Suppose that G is a connected multigraph with n≥
2 vertices, all of even degree. Let x0 = a be a
vertex of even degree. Choose an edge {x0, x1}
incident with a and proceed to build a simple path
{x0, x1}, {x1, x2}, …, {xn-1, xn} by adding edges
one by one until another edge can not be added.
Every vertex in H must have even degree because all the vertices
in G have even degree and for each vertex, pairs of edges incident
with this vertex have been deleted. Beginning with the shared vertex
construct a path ending in the same vertex (as was done before).
Then spliceInthis new circuit
the example, we into the
end up original
with the circuit.
circuit
Continuea,this
f, c,process
d, e, c, b,until
a. all edges have been used. This produces
an Euler circuit. Since every edge is included and no edge is included
more than once.
Sufficient Conditions for Euler
Circuits and Paths
(continued)
Similar reasoning can be used to show
that a graph with exactly two vertices of
odd degree must have an Euler path
connecting these two vertices of odd
degree.
Necessary and Sufficient Conditions
for Euler Circuits and Paths
(continued)
Theorem: A connected multigraph with at least two
vertices has an Euler circuit if and only if each of its
vertices has an even degree and it has an Euler path
if and only if it has exactly two vertices of odd degree.
14
Algorithm for Constructing an
Euler Circuits
In our proof we developed this C
algorithms for constructing a v C'
Euler circuit in a graph with no
vertices of odd degree.
procedure Euler(G : connected multigraph with all vertices of even
degree)
circuit := a circuit in G beginning at an arbitrarily chosen vertex
with edges
successively added to form a path that returns to this
vertex.
H := G with the edges of this circuit removed
while H has edges
subciruit := a circuit in H beginning at a vertex in H that also
is
an endpoint of an edge in circuit.
H := H with edges of subciruit and all isolated vertices removed
circuit := circuit with subcircuit inserted at the appropriate
vertex.
Fleury’s algorithm
Fleury’s algorithm, published in 1883,
constructs Euler circuits by first choosing an
arbitrary vertex of a connected multigraph,
and then forming a circuit by choosing
edges successively. Once an edge is
chosen, it is removed. Edges are chosen
successively so that each edge begins
where the last edge ends, and so that this
edge is not a cut edge unless there is no
alternative.
Fleury 算法(构造 Euler 回路)
设 G = <V , E> 是一个欧拉图
即如果 ei+1 是割边,同时还有
ei+1
2. 设 P0 = v0e1v1e2…eivi ,按下面的方法从
1) ei+1 与 vi 相关联;
Gk = G-{e1,e2,…,ei} 中的桥;
3. 当 Gk 为零图时,算法结束;否则,返回 2 。 17
例
v1 e1 v2 e2 v3
在右图所示的欧拉图中,某人用算法求G中的欧拉回路时,走了简单的回路
: e9 e10 e3
e8
v2e2v3e3v4e14v9e10v2e1v1e8v8e9v2 v8
e1 1 v9 e1 4 v4
之后,无法行遍了,试分析在哪步他犯了错误? e7 e4
e1 2 e1 3
v7 e6 v6 e5 v5
此人行遍 v8 时犯了能不走桥就不走桥的错误,因而未能行遍出欧拉回路。
v1 e1 v2 e2 v3
当他走到 v8 时,G-{ e2 , e3 , e14 , e10 , e1 , e
e8 e9 e10 e3
8 } ,
v8 v4
e1 1 v9 e1 4
见右图,此时, e9 为该图中的桥,而 e7 、 e11 均不是桥。因此,他 e7 e1 2 e1 3 e4
不该走 e9 ,而应该走 e7 或 e11 。但在行遍 v3 和 v1 时,也遇 v7 v5
e6 v6 e5
到桥,为什么没有问题呢? 18
Euler Circuits and Paths in
directed graph
A directed multigraph having no isolated vertices
has an Euler circuit if and only if the graph is
weakly connected and the in-degree and out-
degree of each vertex are equal.
A directed multigraph having no isolated vertices
has an Euler path but not an Euler circuit if and
only if the graph is weakly connected and the in-
degree and out-degree of each vertex are equal
for all but two vertices, one that has in-degree
one larger than its outdegree and the other that
has out-degree one larger than its in-degree.
2 、有向图的欧拉道路、欧拉图
类似于无向图的讨论,对有向图我们有以下结论:
定理
ⅰ )有向连通图 G 含有有向欧拉道路,当且仅当除了两个结点以外,其余结点的入度等于出
度,而这两个例外的结点中,一个结点的入度比出度大 1 ,另一个结点的出度比入度大
1。
ⅱ )有向连通图 G 含有有向欧拉回路,当且仅当 G 中的所有结点的入度等于出度。
V1 V3 V1 V3 V8 V4
V4 V4 V7 V6 V5
(a) (b) (c)
• 图 a) 存在一条的欧拉道路: v3v1v2v3v4v1 ;
因而 (c) 是欧拉图。 21
Applications of Euler Paths
and Circuits
Euler paths and circuits can be used to solve
many practical problems such as finding a path
or circuit that traverses each
street in a neighborhood,
road in a transportation network,
connection in a utility grid,
link in a communications network.
Other applications are found in the
layout of circuits,
network multicasting,
molecular biology, where Euler paths are used in the
sequencing of DNA.
Chinese postman problem
The problem of finding a circuit in a
graph with the fewest edges that
traverses every edge at least once is
known as the Chinese postman problem
in honor of Guan Meigu, who posed it in
1962.
中国邮递员问题
山东师范大学,管梅谷先生 1962 提出并解决。 (参考文献:① 1962 (数学通
报) 81.10,P32, ②< 电子技术应用 >,81.5 )
一个邮递员从邮局出发,在其分管的投递区域内走遍所有的街道把邮件送到每个收件人手
中,最后又回到邮局,要走怎样的线路使全程最短。
4 3 4
3
这个问题用图来表示:街道为图的边,街道交叉口为图的结点, 3
3
2
问题就是要从这样一个图中找出一条至少包含每条边一次的总 2 2
3 3
5
长最短的回路。
4 2
1 1
24
显然,当这个图是欧拉图时,任何一条欧拉回路都符合要求;当这个图不是欧拉图时,所
求回路必然要重复通过某些边。
对此,管梅谷曾证明,若图的边数为 m ,则所求回路的长度最小是 m ,最多不超过
2m ,并且每条边在其中最多出现两次。中国邮递员问题,一般为在带权连通图中找一条包括
全部边的且权最小的回路。
关键是:复制哪些边?
这个问题有着有效的解决办法,其中最直观的方法之一是 : 把图中的某些边复制成两
条边,然后在所求图中找一条欧拉回路。
中国邮递员问题是运筹学中一个典型的优化问题。
25
算法
连通图中,奇数度结点的个数必为
① 若 G 不含奇数度结点,则任一欧拉回路就是问题的解决。
偶数个。
② 若 G 含有 2K(K>0) 个奇数度结点,则先求出其中任何两点间的最短路径,然后再在这些路径
之中找出 K 条路径 P1 , P2 ,…, PK ,使得满足以下条件:
② 构造 G′ 的欧拉回路,即得中国邮递员问题的解。
26
例 13-
1.6
V2
1 .因为 G 含有奇数度结点,所以
3 2
3
2 . G 中有 2K=4(K=2) 个奇结点 V1 , V2 , V3 , V5 。这 V1 1 6 V3
3
3
4 点间的距离
V7
7 5
d(V1,V2)=3 , d(V1,V3)=5 , V6 1 V4
1
2
d(V1,V5)=4 , d(V2,V3)=2 , G
V5
V2
d(V2,V5)=3 , d(V3,V5)=4
3 2 2
各路径 :V1V2(3),V3V5(4)—7 V1 1 3
3 6 V3
3 3
V1V3(5),V2V5(3)—8
V7
7 5
V1V5(4),V2V3(2)—6 V6 1 1 V4
1
2
∴ 两条长度最短 P1=V1V7V5,P2=V2V3 G′
V5
27
3 .构造 G’ 的任一 E 图就是中国邮递员问题的解。
Hamilton Paths and
Circuits
Euler paths and circuits contained every edge
only once. Now we look at paths and circuits
that contain every vertex exactly once.
(1805- 1865)
Hamilton
pentagons as faces),
illustrated in (a), with a peg at
each vertex, labeled with the
names of different cities.
exactly once
Hamilton Paths and
Circuits
The graph form of the puzzle is given in (b).
Solution:
G1 has a Hamilton circuit: a, b, c, d, e, a.
G2 does not have a Hamilton circuit (Why?), but
does have a Hamilton path : a, b, c, d.
G3 does not have a Hamilton circuit, or a Hamilton
path. Why?
Sufficient Conditions for
Hamilton Circuits
Gabriel Andrew
Dirac
Unlike for an Euler circuit, no simple necessary (1925-1984)
and sufficient
conditions are known for the existence of a Hamiton circuit.
However, there are some useful necessary conditions. We
≥3
1968)
(1899-
Ore’s Theorem: If G is a simple graph with n
vertices such that deg(u) + deg(v) ≥ n for every
pair of nonadjacent vertices, then G has a Hamilton
circuit.
此定理表明哈密尔顿
哈密顿图的必要条件 有较好的连通性
33
注意 :
1) 定理 1 给出的是哈密尔顿图的必要条件,而不是充分条件。下图所示的彼得森图
,对 V 的任意非空子集 V1 ,均满足 (G-V1)≤|V1| ,但它不是哈密尔
顿图。
2) 定理 13.3 在应用中它本身用处不大,但它的逆否命题却非常有用。我们经常
利用定理 13.3 的逆否命题来判断某些图不是哈密尔顿图,即:若存在 V 的某
个非空子集 V1 使得 (G-V1) > |V1| ,则 G 不是哈密尔顿图。例如在
该图不是哈密尔顿图。
c
34
哈密顿道路的充分条件
定理 2 设 G = <V , E> 是具有 n 个结点的简单图。如果对任意两个结点
u,v∈V ,均有 deg(u)+deg(v)≥n-1
则 G 中存在哈密尔顿道路。
证明: 1 、首先证明满足上述条件的 G 是连通图。否则 G 至少有两支,即
G1 = <V1 , E1> 和 G2 = <V2 , E2>
对 v1∈V1 , v2 ∈V2 ,
显然 deg(v1) + deg(v2)≤|V1|-1+|V2|-1=n-2
与已知矛盾,故 G 是连通的。
35
证明 ( 续 1)
2 、证明 G 中存在哈密尔顿道路。
设 L = v1v2…vk 为 G 中最长的一条基本道路,显然 k≤n 。
1) 若 k = n ,则 L 为 G 中经过所有结点的道路,即为哈密尔顿道路。
2) 若 k < n ,由 L 的最长性可知, v1 和 vk 的全部邻接点都在 L 上。
Wh
a) 若 v1vkE ,则 v1v2…vkv1 就构成 G 的一个包含 y? L 的圈。
36
证明 ( 续 2)
v1viE vi-1vkE 。
这样就可以构造一个圈 C = v1v2…vi-1vkvk-1…viv1 。
u vk-1
如图所示,这个圈包含了 L 中的全部 v1
vj vi-1 vi vk
结点。
37
证明 ( 续 3)
这样,对 a )和 b ),都可以构造一个包含 L 中的全部结点的一个圈 C 。
由此可以看到,本定理的证明方
因为 k < n ,所以 V 中还有一些结点不在 C 中,由 G 的连通性知,存在 C 外
法是一种构造性证明方法。
的结点 u 与 C 上结点 vj 相邻。显然,可以构造一条基本道路 P′ = uvjvj+1…vi-
38
哈密顿图的充分条件
定理 3 设 G = <V,E> 是具有 n 个结点( n≥3 )的简单图。如果对任意的
两个结点 u,v∈V ,均有
deg(u)+deg(v)≥n
则 G 必是哈密尔顿图。
证明:利用已知条件,仿照定理 13.4 中 b )的方法,可构造出一个包含所有结点的哈
密尔顿圈。
定理 3 给出的是哈密尔顿图的充分条件,而不是必要条件。在六边形中,任意两个结点的度数
之和都是 4 < 6 ,但六边形是哈密尔顿图。
39
例
某地有 5 个风景点,若每个风景点均有两条道路与其他点相通。问游人可否经过每个风景点恰好一
次而游完这 5 处?
解 : 将 5 个风景点看成是有 5 个结点的无向图,两风景点间的道路看成是无向图的边,因为每
处均有两条道路与其他结点相通,故每个结点的度数均为 2 ,从而任意两个结点的度数之和等于
4 ,正好为总结点数减 1 。
故此图中存在一条哈密尔顿道路,因此本题有解。
40
例
证明下图 (a) 所示的图中,不存在哈密尔顿圈。
d d
i i
h j h j
b c
e f
e
(a
f (b
) 中,它的连通分支为
) V1 = {a,b,c} ,得到图 (b) ,在图 (b)
证明在图 (a) 中,删除结点子集
4 ,显然有:
(G-V1) = 4 > |V1| = 3 。由定理 1 可知:图 (a) 所示的图中不会存在哈密尔顿圈,即不是哈密
尔顿图。 41
Applications of Hamilton
Paths and Circuits
Applications that ask for a path or a circuit that visits
each intersection of a city, each place pipelines
intersect in a utility grid, or each node in a
communications network exactly once, can be solved
by finding a Hamilton path in the appropriate graph.
The famous traveling salesperson problem (TSP) asks
for the shortest route a traveling salesperson should
take to visit a set of cities. This problem reduces to
finding a Hamilton circuit such that the total sum of
the weights of its edges is as small as possible.
A family of binary codes, known as Gray codes, which
minimize the effect of transmission errors, correspond
to Hamilton circuits in the n-cube Qn. (See the text for
details.)