Graph Theory Chapter 4 Paths and Distance in Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系...
-
Upload
suzanna-paul -
Category
Documents
-
view
236 -
download
0
Transcript of Graph Theory Chapter 4 Paths and Distance in Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系...
Graph TheoryGraph Theory
Chapter 4Chapter 4 Paths and Distance Paths and Distance in Graphs in Graphs
大葉大學大葉大學 (Da-Yeh (Da-Yeh Univ.)Univ.)資訊工程系資訊工程系 (Dept. (Dept. CSIE)CSIE)黃鈴玲黃鈴玲 (Lingling (Lingling Huang)Huang)
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-22
OutlineOutline
4.1 Distance in Graphs4.1 Distance in Graphs
4.2 Distance in Weighted Graphs4.2 Distance in Weighted Graphs
4.3 The Center and Median of a 4.3 The Center and Median of a GraphGraph
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-33
4.1 Distance in Graphs4.1 Distance in Graphs
G:p5
p4
p7p8
p10 p9
p2
p1
p3
p6
A model of a multiprocessor computer:
A message must be sent from a processor P1 to a processor P2 in the minimum possible amount of time. How can this be done?
10 processors
兩點連線表示彼此可溝通每條邊所需的溝通時間相同
Find shortest P1-P2 paths.
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-44
Definition:Definition:
For a nontrivial graph G and a pair u, v of vertices of G, the distance dG(u, v) (or d(u, v) if the graph G is clear from context) between u and v is the length of a shortest u-v path in G if such a path exists.
If G contains no u-v path, then we define d(u, v) = ∞.
G1:
vu
G2:
yx
d(x, y) = ∞d(u, v) = 2
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-55
Definition:Definition: The distance function on a graph G is a The distance function on a graph G is a
metricmetric, that is, it maps V(G), that is, it maps V(G)V(G) to the set V(G) to the set of nonnegative integers and satisfies the of nonnegative integers and satisfies the following fundamental properties: (following fundamental properties: ( 接下頁接下頁 ))
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-66
Thm 4.1:Thm 4.1: Let G be a graph. ThenLet G be a graph. Then
(i) d (u, v) (i) d (u, v) 0, and d (u, v) = 0 iff u = v;0, and d (u, v) = 0 iff u = v;
(ii) d (u, v) = d (v, u) for all u, v (ii) d (u, v) = d (v, u) for all u, v V(G); V(G);
(iii) d (u, v) (iii) d (u, v) d (u, w) + d (w, v) for all d (u, w) + d (w, v) for all u, v, u, v,
w w V(G) ( V(G) (the triangle inequalitythe triangle inequality).).Pf: [(i) and (ii), see problem 1.]
(iii), we proceed as follows: Let u, v, and w be vertices of G. Let P be a shortest u – w path and Q a shortest w –v path in G. Then P followed by Q is a u – v walk, say W, having length d (u, w) + d (w, v). Since W contains a d (u, w) + d (w, v). Since W contains a u u –– v path (by thm1.3), it follows that d (u, v) v path (by thm1.3), it follows that d (u, v) d (u, w) + d (w, v) d (u, w) + d (w, v).
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-77
Definition:Definition: For a directed graphFor a directed graph DD, , the (directed)the (directed)
distancedistance ddDD((uu, , vv)) (or (or dd((uu, , vv)) )) from vertex from vertex uu to vertex to vertex vv of of DD is the length of a is the length of a shortest directed shortest directed u-vu-v path if such a path if such a path exists, and is path exists, and is ∞ ∞ otherwise.otherwise.
D:
zw
x
v
u
y
dd((uu, , vv) = ∞) = ∞
dd((uu, , zz) = 3) = 3
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-88
Algorithm 4.1 (MooreAlgorithm 4.1 (Moore’’s s Breadth-First Search Breadth-First Search Algorithm)Algorithm)
1.1. For every vertex For every vertex w w u u, let , let ll((ww)) ← ∞. ← ∞. Further, let Further, let ll((uu) ) ← 0← 0 and initialize the queue and initialize the queue QQ to contain to contain uu only. only.
2.2. If If QQ , then delete a vertex , then delete a vertex xx from from QQ; ; otherwise, stop, since there is no otherwise, stop, since there is no u-vu-v path. path.
3.3. For every vertex For every vertex yy adjacent with adjacent with x x such that such that ll((yy) = ∞,) = ∞, assign assign PARENTPARENT((yy)) ← ← xx, let, let ll((yy)) ← ← ll((xx)) +1 and add +1 and add y y to to QQ..
4.4. If If ll((vv)) =∞, then return Step 2; otherwise, go to Step =∞, then return Step 2; otherwise, go to Step 5.5.
5.5. 5.1 Let 5.1 Let kk ← ← ll((vv)) and and uukk ← ← vv. . 5.2 If 5.2 If kk 0, then 0, then uukk11 ← ← PARENTPARENT((uukk);); otherwise go to Step 5.4.otherwise go to Step 5.4. 5.3 Let 5.3 Let k k ←← k k 11 and go to Step 5.2. and go to Step 5.2. 5.4 Output 5.4 Output uu00, u, u11, …, u, …, ukk, which is a shortest , which is a shortest u–vu–v path. path.
(For given uv, find d(u,v) and a shortest u-v path.)
l(v) 即是 d(u,v)
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-99
Algorithm 4.2Algorithm 4.2
1. For every vertex v u, let l(u) ← .Further, let l(u) ← 0 and add u to a queue Q.
2. If Q , then delete a vertex x from Q and go to Step 4.
3. If Q = , then output the pairs v, l(v) for all vertices v of G, and stop.
4. For every vertex y adjacent to x such that l(y) = ,let l(y) ← l(x) +1 and add y to Q. Return to Step 2.
(To find d(u,v) for a fixed vertex u and every vertex v.)
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1010
v3
v1
v6
v2
v9v8
v5
v4
v10
u
v7
G:
v3
v1 v2
v9v8
v4 v10
u
v7
u v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
0
0 1 1 1
v5
v6
0 1 1 12 2 2 2
3 0 1 1 12 2 2 2
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1111
HomeworkHomework
Exercise 4.1: Exercise 4.1: 2, 5 2, 5
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1212
OutlineOutline
4.1 Distance in Graphs4.1 Distance in Graphs
4.2 Distance in Weighted Graphs4.2 Distance in Weighted Graphs
4.3 The Center and Median of a 4.3 The Center and Median of a GraphGraph
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1313
4.2 DISTANCE IN WEIGHTED GRAPHS4.2 DISTANCE IN WEIGHTED GRAPHS
v3
v1
v6
v2h
v8
v5v4
a
v7
11
20
20
1015
15
20
40
10
30
20
15
20
15
a: accident scene (destination)h: hospital (source)other vertices: intersections of roadsedge: roadedge weight: number of seconds needed to travel the road.
A model of routes from a hospital to an accident scene.
Q: 如何最快從 h 到達 a?
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1414
Definition 1:Definition 1: The The distance distance dd((uu, , vv)) between a pair between a pair uu, , vv
of vertices of of vertices of GG is the minimum length is the minimum length (weight) of all (weight) of all u-vu-v path in path in GG, if any such , if any such paths exist; otherwise, paths exist; otherwise, dd((uu, , vv) = ) = .
3u
G:
3
z
y
x
v
11 2
4 838
d(u, v)=10
P: u, x, y, v is a shortest path.
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1515
Algorithm 4.3 (DijkstraAlgorithm 4.3 (Dijkstra’’s s Algorithm)Algorithm)
1.1. Let Let ii ← 0, ← 0, SS ← { ← {u0}, ← }, ← VV((GG) ) { {u0}, }, l(u0) ← 0 and assign l(v) ← for all v V(G) {{u0}. }. If If pp = 1, then stop; otherwise, continue. = 1, then stop; otherwise, continue.
2.2. For each For each vv such that ui v E(G), proceed as follows: If l(v) l(ui) + w(ui, v), then continue; otherwise, l(v) ←← l(ui) + w(ui, v), and PARENT(v) ← ui .
3.3. Determine Determine mm = = minmin{ { l(v) || v v }. If }. If vvjj is selected is selected as a vertex with as a vertex with l((vvjj) = ) = mm, then output , then output mm as the as the distance between distance between uu00 and and vvjj, and , and ui+1+1 ← ← vvjj..
4.4. SS ← ← SS { {ui+1+1} } and and ← ← { {ui+1+1}.}.
5.5. i i ←← i i + 1. If + 1. If i i = = pp –– 1, then stop; 1, then stop; otherwise, return to Step 2. otherwise, return to Step 2.
S
(For a vertex u0, determine d(u0,v) for any vertex v.)
S
(S: 目前為止跟 u0 距離已經決定的點 ; l(v): v 跟 u0 目前的距離 )
S S
S S
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1616
v4
v3
v1
v6
v2
16
v5
u0
v7
10
11
13
65
17
14
97
8Figure 4-7
l(u0) v1 v2 v3 v4 v5 v6 v7 added to S0 (, -) (, -) (, -) (, -) (, -) (, -) (, -) u0
(13, u0)
(, -) (, -) (, -) (, -)(16, u0)
(8, u0)
(, -) (, -)
v5
(18, v5) (13, u0)
(25, v5) (15, v5) v2
(25, v5) (15, v5)(18, v5) (, -) (, -) v4
(20, v4)(18, v5) (, -) (, -) v1
(20, v4) (, -) (, -) v3
(, -) (, -)
minimum
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1717
Thm 4.2:Thm 4.2: Let Let GG be a weight graph of order be a weight graph of order pp. .
DijkstraDijkstra’’s algorithm determines the distance s algorithm determines the distance from a fixed vertex from a fixed vertex uu00 of of GG to every vertex of to every vertex of GG. . That is, when the algorithm terminates, That is, when the algorithm terminates,
ll((vv) = ) = dd((uu00, , vv)) for all for all vv VV((GG). ).
Further, if Further, if ll((vv) ) ∞ and ∞ and vv uu00, then, then
uu0 = 0 = ww00, , ww11, , ww2 2 ,…, ,…, wwkk = = vv
is a shortest is a shortest uu0 0 – – vv path, where path, where wwii-1 -1 = = PARENTPARENT ( (wwii)) for for ii = 1, 2, = 1, 2, ……, k., k.
Pf: (book P.108)
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1818
HomeworkHomework
Exercise 4.2: Exercise 4.2: 1, 3 1, 3
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-1919
OutlineOutline
4.1 Distance in Graphs4.1 Distance in Graphs
4.2 Distance in Weighted Graphs4.2 Distance in Weighted Graphs
4.3 The Center and Median of a 4.3 The Center and Median of a GraphGraph
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2020
4.3 4.3 THE CENTER AND MEDIAN THE CENTER AND MEDIAN OF A GRAPHOF A GRAPH
G:
A model of a street system:
Q: How to place the police station, fire station, newspaper distributing depot and post office?
edge: streetvertex: intersection
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2121
Two different criterions:(1) police station, fire station: minimize the response time between thefacility and the location of a possible emergency( 以出發後能最快到達事故地點為訴求 )(choose x to minimize max{d(x,v) | v V(G) }) (2) newspaper distributing depot, post office: minimize the average of the travel distancesneeded to reach every building
How to choose the locations?How to choose the locations?
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2222
Definition:Definition:
The The eccentricityeccentricity ee(v)(v) of a vertex v in a of a vertex v in a graph (or weighted graph) G is the graph (or weighted graph) G is the distance from v to a vertex furthest from distance from v to a vertex furthest from v, that is,v, that is,
ee(v) = max{ d(v, u)| u (v) = max{ d(v, u)| u V(G)}. V(G)}.
2 3
4
43
3
2
10
10
10
11
11
10
8All eccentricities of GAll eccentricities of G11::
G1
:
All eccentricities of GAll eccentricities of G22::
G2
: 2
41
3
21
75
6
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2323
Definition:Definition: (1) The The radiusradius rad(rad(GG)) of a connected graph of a connected graph
(or weighted graph) G is defined as (or weighted graph) G is defined as
rad(rad(GG) = min { ) = min { ee((vv) | ) | v v VV((GG)}.)}.
(2)(2) The The diameterdiameter diam(diam(GG)) of a connected of a connected graph (or weighted graph) graph (or weighted graph) GG is defined is defined byby
diam(diam(GG) = max{ ) = max{ ee((vv) | ) | v v VV((GG)}.)}.
上一頁: rad(rad(GG11) = 2, diam() = 2, diam(GG11) = 4) = 4 rad(rad(GG22) = 8, diam() = 8, diam(GG22) = 11) = 11
Note. 書上寫成 rad G 及 diam G.
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2424
Thm 4.3:Thm 4.3:
Let Let GG be a graph. Then be a graph. Then
rad(G) ≦ diam(G) ≦ 2 rad(G).rad(G) ≦ diam(G) ≦ 2 rad(G).
pf:
The left inequality follows directly from the definition. To verify the right inequality let u, v V(G) V(G) such that d (u, v) = diam G. Let w be a vertex with ee(w) = rad G. By Thm 4.1, (w) = rad G. By Thm 4.1, diam G = d (u, v)diam G = d (u, v) ≦ d (u, w) + ≦ d (u, w) + d (w, d (w, v) ≦ 2rad G. This establishes the right v) ≦ 2rad G. This establishes the right inequality.
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2525
Definition:Definition:
TheThe center center CC((GG)) of a connected graph of a connected graph (or weighted graph) (or weighted graph) GG is the subgraph is the subgraph induced by the vertices of induced by the vertices of GG whose whose eccentricity equals the radius of eccentricity equals the radius of GG. .
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2626
Thm 4.4:Thm 4.4:
Every graph is the center of some Every graph is the center of some connected graph.connected graph.
Pf:
Let H be a given graph. We begins by adding four additional vertices to H. Join v1 and v2 to all vertices in H, join u1 only to v1 and u2 only to v2.
For every vertex v in H, the eccentricity eG(v) = 2,
and eG(v1) = eG(v2) = 3 and eG(u1) = eG(u2) = 4 (see problem 4). Since rad(G) = 2 , the center of G is the subgraph induced by the vertices of H, that is, C(G)=H.
G:v1 u2u1 v2
H
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2727
Algorithm 4.4Algorithm 4.4
1.1. Set Set T’T’ = = TT..
2.2. If If T’T’ KK11 oror KK22, then , then CC((TT)) = T’ = T’; ; otherwise, proceed to Step 3.otherwise, proceed to Step 3.
3.3. Delete each vertex of degree 1 in Delete each vertex of degree 1 in T’T’ to obtain a treeto obtain a tree TT””.. Set Set T’ ←TT’ ←T”” and and return to Step 2.return to Step 2.
(To determine the center C(T) of a given tree T.)
( 作法:一層一層從外往內剝掉 )
Thm 4.5:Thm 4.5: TThe center of every tree he center of every tree is is isomorphic to isomorphic to KK11 or or KK22..
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2828
Definition:Definition: The The distance distance dd((vv) of a vertex) of a vertex vv in a in a
graph or weighted graph graph or weighted graph GG is the sum of is the sum of the distances from the distances from vv to each vertex of to each vertex of GG..
G: u
w y
xv
z
VerteVertexx
DistancDistancee
uu 99vv 88ww 77xx 88yy 77zz 1111
※ To minimize the sum of the distancesfrom the depot to each street intersection:
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-2929
Definition:Definition: The The median median MM((GG)) of a graph is subgraph of a graph is subgraph
induced by the set of vertices having induced by the set of vertices having minimum distance. (minimum distance. ( 到所有點總距離最短到所有點總距離最短 ))
H:
u w
y
xv t
z C(H) = <{w}>
M(H) = <{x}>
s
Copyright Copyright 黃鈴玲黃鈴玲Ch4-Ch4-3030
HomeworkHomework
Exercise 4.3:Exercise 4.3:3, 4, 7, 10, 11, 123, 4, 7, 10, 11, 12