1 / 30

Graph Theory Chapter 4 Paths and Distance in Graphs

Graph Theory Chapter 4 Paths and Distance in Graphs. 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang). Outline. 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph. G:. p 3. p 4. p 5. p 1. p 8. p 7. p 2. p 6. p 10. p 9.

gdorsey
Download Presentation

Graph Theory Chapter 4 Paths and Distance in Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph

  3. G: p3 p4 p5 p1 p8 p7 p2 p6 p10 p9 4.1 Distance in Graphs A model of a multiprocessor computer: 10 processors 兩點連線表示彼此可溝通 每條邊所需的溝通時間相同 A message must be sent from a processor P1to a processorP2in the minimum possible amount of time. How can this be done?  Find shortest P1-P2paths.

  4. G2: G1: x y u v Definition: For a nontrivial graphGand a pairu, vof vertices ofG, thedistancedG(u, v)(ord(u, v)if thegraphGis clear from context)betweenuandvis the length of a shortestu-vpath inGif such a path exists. IfGcontains nou-vpath, then we defined(u, v) = ∞. d(x, y) = ∞ d(u, v) = 2

  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: (接下頁)

  6. Thm 4.1: Let G be a graph. Then (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); (iii) d (u, v) d (u, w) + d (w, v) for all u, v, w  V(G) (the 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 u – v path (by thm1.3), it follows that d (u, v)  d (u, w) + d (w, v).

  7. v D: x u z w y Definition: For a directed graphD, the (directed)distancedD(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(u, v) = ∞ d(u, z) = 3

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

  9. Algorithm 4.2 (To find d(u,v) for a fixed vertex u and every vertex v.) • For every vertex vu, let l(u) ← .Further, let l(u) ← 0 and add u to a queue Q. • If Q , then delete a vertex x from Q and go to Step 4. • If Q = , then output the pairs v, l(v) for all vertices v of G, and stop. • 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.

  10. u u v5 v2 v1 G: v1 v3 v2 v4 v3 v4 v6 v10 v6 v5 v7 v7 v8 v9 v8 v9 v10 u v1 v2 v3 v4 v5 v6 v7 v8 v9 v10           0           1 1 1 0   1 1 2 2 1 2 2 0 1 1 1 0 2 2 2 2 3

  11. Homework • Exercise 4.1: 2, 5

  12. Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph

  13. v4 v5 15 10 v7 20 v6 20 15 10 v1 20 15 20 v8 v3 40 20 15 11 h v2 30 a 4.2 DISTANCE IN WEIGHTED GRAPHS A model of routes from a hospital to an accident scene. a: accident scene (destination)h: hospital (source)other vertices: intersections of roadsedge: roadedge weight: number of seconds needed to travel the road. Q: 如何最快從h到達a?

  14. z G: 11 2 3 u y v 8 3 4 3 8 x 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) = . d(u, v)=10 P: u, x, y, vis a shortest path.

  15. Algorithm 4.3 (Dijkstra’s Algorithm) (For a vertex u0, determine d(u0,v) for any vertex v.) • Let i ← 0, S ← {u0}, ← V(G) - {u0}, l(u0) ← 0 and assign l(v) ←  for all v  V(G) -{u0}. If p = 1, then stop; otherwise, continue. • For each v 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 . • Determine m = min{ l(v)| v }. If vj is selected as a vertex with l(vj) = m, then output m as the distance between u0 and vj, and ui+1 ← vj. • S ← S {ui+1} and ← - {ui+1}. • i ← i + 1. If i = p– 1, then stop; otherwise, return to Step 2. (S: 目前為止跟u0距離已經決定的點; l(v): v 跟u0目前的距離)

  16. minimum l(u0) v2 v3 v4 v5 v6 v7 added to S v1 (, -) (, -) (, -) (, -) (, -) (, -) (, -) 0 (, -) (, -) (, -) (, -) (, -) (, -) (18, v5) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) u0 Figure 4-7 8 v1 16 v5 10 13 v7 v6 9 11 7 17 v2 6 v4 14 5 v3 u0 (13, u0) (16, u0) (8, u0) v5 v2 (18, v5) (13, u0) (25, v5) (15, v5) v4 (25, v5) (15, v5) v1 (18, v5) (20, v4) v3 (20, v4)

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

  18. Homework Exercise 4.2: 1, 3

  19. Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph

  20. G: 4.3 THE CENTER AND MEDIAN OF A GRAPH A model of a street system: edge: streetvertex: intersection Q: How to place the police station, fire station, newspaper distributing depot and post office?

  21. How to choose the locations? 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

  22. G2: 8 3 10 3 G1: 2 10 2 2 1 4 7 5 10 1 11 4 11 6 3 3 4 2 10 Definition: The eccentricitye(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)}. All eccentricities of G2: All eccentricities of G1:

  23. Definition: (1)The radiusrad(G) of a connected graph (or weighted graph) G is defined as rad(G) = min { e(v) | v V(G)}. (2) The diameterdiam(G) of a connected graph (or weighted graph) G is defined by diam(G) = max{ e(v) | v V(G)}. 上一頁: rad(G1) = 2, diam(G1) = 4rad(G2) = 8, diam(G2) = 11 Note. 書上寫成 rad G 及 diam G.

  24. Thm 4.3: Let G be a graph. Then 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) 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. 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.

  26. G: u1 v1 v2 u2 H Thm 4.4: 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 v1 and v2 to all vertices in H, joinu1 only tov1 and u2 only to v2. For every vertex v in H, the eccentricity eG(v) = 2, and eG(v1) = eG(v2) = 3and 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.

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

  28. x v G: u w y z ※ To minimize the sum of the distancesfrom the depot to each street intersection: Definition: The distance d(v) of a vertexv in a graph or weighted graph G is the sum of the distances from v to each vertex of G.

  29. Definition: The median M(G) of a graph is subgraph induced by the set of vertices having minimum distance. (到所有點總距離最短) y H: C(H) = <{w}> M(H) = <{x}> z t u v w x s

  30. Homework Exercise 4.3:3, 4, 7, 10, 11, 12

More Related