大叶大学学习课件.pptVIP

  • 1
  • 0
  • 约8.63千字
  • 约 30页
  • 2016-12-06 发布于江苏
  • 举报
Graph Theory Chapter 4 Paths and Distance in Graphs 大葉大學 資訊工程系 黃鈴玲 Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Graph 4.1 Distance in Graphs 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) = ∞. 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: (接下頁) Definition: For a directed graph D, the (directed) distance dD(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. Algorithm 4.1 (Moore’s Breadth-First Search Algorithm) For every vertex w ? u, let l(w) ← ∞. Further, let l(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, let l(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, then uk-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. Algorithm 4.2 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. Homework Exercise 4.1: 2, 5 Outline 4.1 Distance in Graphs 4.2 Distance in Weighted Graphs 4.3 The Center and Median of a Grap

文档评论(0)

1亿VIP精品文档

相关文档