Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graph Theory Chapter 4 Paths and Distance in Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)

Similar presentations


Presentation on theme: "Graph Theory Chapter 4 Paths and Distance in Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)"— Presentation transcript:

1 Graph Theory Chapter 4 Paths and Distance in Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)

2 Copyright  黃鈴玲 Ch4-2 Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph

3 Copyright  黃鈴玲 Ch4-3 4.1 Distance in Graphs G: p5p5 p4p4 p7p7 p8p8 p 10 p9p9 p2p2 p1p1 p3p3 p6p6 A model of a multiprocessor computer: A message must be sent from a processor P 1 to a processor P 2 in the minimum possible amount of time. How can this be done? 10 processors 兩點連線表示 彼此可溝通 每條邊所需的 溝通時間相同  Find shortest P 1 - P 2 paths.

4 Copyright  黃鈴玲 Ch4-4 Definition: For a nontrivial graph G and a pair u, v of vertices of G, the distance d G (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:G1: vu G2:G2: y x d(x, y) = ∞ d(u, v) = 2

5 Copyright  黃鈴玲 Ch4-5 Definition: The distance function on a graph G is a metric, that is, it maps V(G)  V(G) to the set of nonnegative integers and satisfies the following fundamental properties: ( 接下頁 ) The distance function on a graph G is a metric, that is, it maps V(G)  V(G) to the set of nonnegative integers and satisfies the following fundamental properties: ( 接下頁 )

6 Copyright  黃鈴玲 Ch4-6 Thm 4.1: Let G be a graph. Then Let G be a graph. Then (i) d (u, v)  0, and d (u, v) = 0 iff u = v; (i) d (u, v)  0, and d (u, v) = 0 iff u = v; (ii) d (u, v) = d (v, u) for all u, v  V(G); (ii) d (u, v) = d (v, u) for all u, v  V(G); (iii) d (u, v)  d (u, w) + d (w, v) for all u, v, (iii) d (u, v)  d (u, w) + d (w, v) for all u, v, w  V(G) (the triangle inequality). w  V(G) (the triangle inequality). Pf: [(i) and (ii), see problem 1.] d (u, w) + d (w, v). Since W contains a u – v path (by thm1.3), it follows that d (u, v)  d (u, w) + d (w, v) (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 u – v path (by thm1.3), it follows that d (u, v)  d (u, w) + d (w, v).

7 Copyright  黃鈴玲 Ch4-7 Definition: For a directed graph D, the (directed) distance d D (u, v) (or d ( u, v )) from vertex u to vertex v of D is the length of a shortest directed u-v path if such a path exists, and is ∞ otherwise. For a directed graph D, the (directed) distance d D (u, v) (or d ( u, v )) from vertex u to vertex v of D is the length of a shortest directed u-v path if such a path exists, and is ∞ otherwise. D: z w x v u y d(u, v) = ∞ d(u, z) = 3

8 Copyright  黃鈴玲 Ch4-8 Algorithm 4.1 (Moore ’ s Breadth-First Search Algorithm) 1.For every vertex w  u, let l(w) ← ∞. Further, let l(u) ← 0 and initialize the queue Q to contain u only. 2.If Q  , then delete a vertex x from Q ; otherwise, stop, since there is no u-v path. 3.For every vertex y adjacent with x such that l(y) = ∞, assign PARENT(y) ← x, let l(y) ← l(x) +1 and add y to Q. 4.If l(v) =∞, then return Step 2; otherwise, go to Step 5. 5.5.1 Let k ← l(v) and u k ← v. 5.2 If k  0, then u k  1 ← PARENT(u k ); 5.2 If k  0, then u k  1 ← PARENT(u k ); otherwise go to Step 5.4. otherwise go to Step 5.4. 5.3 Let k ← k  1 and go to Step 5.2. 5.3 Let k ← k  1 and go to Step 5.2. 5.4 Output u 0, u 1, …, u k, which is a shortest u–v path. 5.4 Output u 0, u 1, …, u k, which is a shortest u–v path. (For given u  v, find d(u,v) and a shortest u-v path.) l(v) 即是 d(u,v)

9 Copyright  黃鈴玲 Ch4-9 Algorithm 4.2 1. 1.For every vertex v  u, let l ( u ) ← .Further, let l ( u ) ← 0 and add u to a queue Q. 2. 2.If Q  , then delete a vertex x from Q and go to Step 4. 3. 3.If Q = , then output the pairs v, l(v) for all vertices v of G, and stop. 4. 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.)

10 Copyright  黃鈴玲 Ch4-10 v3v3 v1v1 v6v6 v2v2 v9v9 v8v8 v5v5 v4v4 v 10 u v7v7 G:G: v3v3 v1v1 v2v2 v9v9 v8v8 v4v4 u v7v7 uv1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 v9v9 0  0 111  v5v5 v6v6 0 111222  2 3  0 1112222

11 Copyright  黃鈴玲 Ch4-11 Homework Exercise 4.1: 2, 5 Exercise 4.1: 2, 5

12 Copyright  黃鈴玲 Ch4-12 Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph

13 Copyright  黃鈴玲 Ch4-13 4.2 DISTANCE IN WEIGHTED GRAPHS v3v3 v1v1 v6v6 v2v2 h v8v8 v5v5 v4v4 a v7v7 11 20 10 15 20 40 10 30 2015 20 15 a: accident scene (destination) h: hospital (source) other vertices: intersections of roads edge: road edge weight: number of seconds needed to travel the road. A model of routes from a hospital to an accident scene. Q: 如何最快從 h 到達 a?

14 Copyright  黃鈴玲 Ch4-14 Definition 1: The distance d(u, v) between a pair u, v of vertices of G is the minimum length (weight) of all u-v path in G, if any such paths exist; otherwise, d(u, v) = The distance d(u, v) between a pair u, v of vertices of G is the minimum length (weight) of all u-v path in G, if any such paths exist; otherwise, d(u, v) = . 3 u G: 3 z y x v 11 2 4 83 8 d(u, v)=10 P: u, x, y, v is a shortest path.

15 Copyright  黃鈴玲 Ch4-15 Algorithm 4.3 (Dijkstra ’ s Algorithm) 1.Let i ← 0, S ← {}, ← V ( G )  {}, {}. If p = 1, then stop; otherwise, continue. 1.Let i ← 0, S ← { u 0 }, ← V ( G )  { u 0 }, l ( u 0 ) ← 0 and assign l ( v ) ←  for all v  V ( G )  { u 0 }. If p = 1, then stop; otherwise, continue. 2.For each v ← 2.For each v  such that u i v  E ( G ), proceed as follows: If l(v)  l(u i ) + w(u i, v), then continue; otherwise, l(v) ← l(u i ) + w(u i, v), and PARENT ( v ) ← u i. 3.Determine m = min { | v }. If v j is selected as a vertex with (v j ) = m, then output m as the distance between u 0 and v j, and +1 ← v j. 3.Determine m = min { l(v) | v  }. If v j  is selected as a vertex with l(v j ) = m, then output m as the distance between u 0 and v j, and u i +1 ← v j. 4.S ← S  { +1 } and ←  { +1 }. 4.S ← S  {u i+1 } and ←  {u i+1 }. 5.i ← i + 1. If i = p – 1, then stop; otherwise, return to Step 2. (For a vertex u 0, determine d ( u 0,v ) for any vertex v.) ( S : 目前為止跟 u 0 距離已經決定的點 ; l(v): v 跟 u 0 目前的距離 )

16 Copyright  黃鈴玲 Ch4-16 v4v4 v3v3 v1v1 v6v6 v2v2 16 v5v5 u0u0 v7v7 10 11 13 6 5 17 14 9 7 8 Figure 4-7 l(u0)l(u0) v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 added to S 0 ( , -) u0u0 (13, u 0 ) ( , -) (16, u 0 )(8, u 0 ) ( , -) v5v5 (18, v 5 )(13, u 0 )(25, v 5 )(15, v 5 ) v2v2 (25, v 5 )(15, v 5 )(18, v 5 ) ( , -) v4v4 (20, v 4 )(18, v 5 ) ( , -) v1v1 (20, v 4 ) ( , -) v3v3 minimum

17 Copyright  黃鈴玲 Ch4-17 Thm 4.2: Let G be a weight graph of order p. Dijkstra ’ s algorithm determines the distance from a fixed vertex u 0 of G to every vertex of G. That is, when the algorithm terminates, Let G be a weight graph of order p. Dijkstra ’ s algorithm determines the distance from a fixed vertex u 0 of G to every vertex of G. That is, when the algorithm terminates, l(v) = d(u 0, v) for all v  V ( G ). l(v) = d(u 0, v) for all v  V ( G ). Further, if l ( v )  ∞ and v  u 0, then Further, if l ( v )  ∞ and v  u 0, then u 0 = w 0, w 1, w 2,…, w k = v u 0 = w 0, w 1, w 2,…, w k = v is a shortest u 0 – v path, where w i-1 = PARENT (w i ) for i = 1, 2, …, k. is a shortest u 0 – v path, where w i-1 = PARENT (w i ) for i = 1, 2, …, k. Pf: (book P.108)

18 Copyright  黃鈴玲 Ch4-18 Homework Exercise 4.2: 1, 3

19 Copyright  黃鈴玲 Ch4-19 Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph

20 Copyright  黃鈴玲 Ch4-20 4.3 THE CENTER AND MEDIAN OF 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: street vertex: intersection

21 Copyright  黃鈴玲 Ch4-21 Two different criterions: (1) police station, fire station: minimize the response time between the facility 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 distances needed to reach every building How to choose the locations?

22 Copyright  黃鈴玲 Ch4-22 Definition: The eccentricity e (v) of a vertex v in a graph (or weighted graph) G is the distance from v to a vertex furthest from v, that is, The eccentricity e (v) of a vertex v in a graph (or weighted graph) G is the distance from v to a vertex furthest from v, that is, e (v) = max{ d(v, u)| u  V(G)}. e (v) = max{ d(v, u)| u  V(G)}. 2 3 4 43 3 2 10 11 10 8 All eccentricities of G 1 : G1:G1: All eccentricities of G 2 : G2:G2: 2 4 1 3 2 1 7 5 6

23 Copyright  黃鈴玲 Ch4-23 Definition: The radius rad( G ) of a connected graph (or weighted graph) G is defined as (1) The radius rad( G ) of a connected graph (or weighted graph) G is defined as rad( G ) = min { e ( v ) | v  V ( G )}. rad( G ) = min { e ( v ) | v  V ( G )}. (2) The diameter diam( G ) of a connected graph (or weighted graph) G is defined by (2) The diameter diam( G ) of a connected graph (or weighted graph) G is defined by diam( G ) = max{ e ( v ) | v  V ( G )}. diam( G ) = max{ e ( v ) | v  V ( G )}. rad( G 1 ) = 2, diam( G 1 ) = 4 rad( G 2 ) = 8, diam( G 2 ) = 11 上一頁: rad( G 1 ) = 2, diam( G 1 ) = 4 rad( G 2 ) = 8, diam( G 2 ) = 11 Note. 書上寫成 rad G 及 diam G.

24 Copyright  黃鈴玲 Ch4-24 Thm 4.3: Let G be a graph. Then Let G be a graph. Then rad(G) ≦ diam(G) ≦ 2 rad(G). rad(G) ≦ diam(G) ≦ 2 rad(G). pf:  V(G) e (w) = rad G. By Thm 4.1, diam G = d (u, v) ≦ d (u, w) + d (w, v) ≦ 2rad G. This establishes the right The left inequality follows directly from the definition. To verify the right inequality let u, v  V(G) such that d (u, v) = diam G. Let w be a vertex with e (w) = rad G. By Thm 4.1, diam G = d (u, v) ≦ d (u, w) + d (w, v) ≦ 2rad G. This establishes the right inequality.

25 Copyright  黃鈴玲 Ch4-25 Definition: The center C(G) of a connected graph (or weighted graph) G is the subgraph induced by the vertices of G whose eccentricity equals the radius of G. The center C(G) of a connected graph (or weighted graph) G is the subgraph induced by the vertices of G whose eccentricity equals the radius of G.

26 Copyright  黃鈴玲 Ch4-26 Thm 4.4: Every graph is the center of some connected graph. Every graph is the center of some connected graph. Pf: Let H be a given graph. We begins by adding four additional vertices to H. Join v 1 and v 2 to all vertices in H, join u 1 only to v 1 and u 2 only to v 2. For every vertex v in H, the eccentricity e G ( v ) = 2, and e G ( v 1 ) = e G ( v 2 ) = 3 and e G ( u 1 ) = e G ( u 2 ) = 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:G: v1v1 u2u2 u1u1 v2v2 H

27 Copyright  黃鈴玲 Ch4-27 Algorithm 4.4 1.Set T’ = T. 2.If T’  K 1 or K 2, then C(T) = T’ ; otherwise, proceed to Step 3. 3.Delete each vertex of degree 1 in T’ to obtain a tree T”. Set T’ ←T” and return to Step 2. (To determine the center C(T) of a given tree T.) ( 作法:一層一層從外往內剝掉 ) Thm 4.5: The center of every tree is isomorphic to K 1 or K 2.

28 Copyright  黃鈴玲 Ch4-28 Definition: The distance d ( v ) of a vertex v in a graph or weighted graph G is the sum of the distances from v to each vertex of G. The distance d ( v ) of a vertex v in a graph or weighted graph G is the sum of the distances from v to each vertex of G. G: u wy x v z VertexDistance u9 v8 w7 x8 y7 z11 ※ To minimize the sum of the distances from the depot to each street intersection:

29 Copyright  黃鈴玲 Ch4-29 Definition: The median M(G) of a graph is subgraph induced by the set of vertices having minimum distance. ( 到所有點總距離最短 ) The median M(G) of a graph is subgraph induced by the set of vertices having minimum distance. ( 到所有點總距離最短 ) H: uw y xv t z C(H) = M(H) = s

30 Copyright  黃鈴玲 Ch4-30 Homework Exercise 4.3: 3, 4, 7, 10, 11, 12


Download ppt "Graph Theory Chapter 4 Paths and Distance in Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)"

Similar presentations


Ads by Google