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

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Lecture 5 Graph Theory. Graphs Graphs are the most useful model with computer science such as logical design, formal languages, communication network,
Colorings of graphs and Ramsey’s theorem
A Better Algorithm for Finding Planar Subgraph Gruia Călinescu Cristina G. Fernandes Ulrich Finkler Howard Karloff.
Chapter 3 Determinants and Eigenvectors 大葉大學 資訊工程系 黃鈴玲 Linear Algebra.
Graph Theory Chapter 9 Planar Graphs 大葉大學 資訊工程系 黃鈴玲.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
: ACM CONTEST AND BLACKOUT ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10600: ACM CONTEST AND BLACKOUT 解題者:洪光燦 解題日期: 2006 年 6 月 12 日 題意:每個學校都需要電力,但是只有一台發電.
Applied Discrete Mathematics Week 12: Trees
: Road Construction ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 10724: Road Construction 解題者:徐文宏 解題日期: 2011 年 4 月 20 日 題意:給一個座標圖 (-1000~1000)
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Graph V(G 1 )={0, 1, 2, 3, 4, 5, 6, 7, 8, 9} E(G 1 )={(0, 2), (0, 3), (1, 4), (2, 3), (2, 5), (2, 6), (3, 6), (3, 7), (4, 7), (5, 6), (5,
Graph Theory Graph theory is the study of the properties of graph structures. It provides us with a language with which to talk about graphs.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Johnson’s algorithm Johnson’s演算法可用於計算All pairs shortest path問題。
最短路徑演算法 卓訓榮 2002/11/11 Data base Label Setting Algorithm Label Correcting Algorithm 運輸資訊.
Single-Source Shortest Paths
: Flea circus ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10938: Flea circus 解題者:李育賢 解題日期: 2008 年 6 月 6 日 題意:題目會給定一些點當做樹與樹枝或樹葉連 接的地方 ( 最多.
: 05-2 Rendezvous ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11015: 05-2 Rendezvous 解題者:池明洋 解題日期: 2006 年 4 月 16 日 題意: 給 node N 個 , edge.
指導教授:張玉盈 教授 學生:黃意涵、林宜融、許蕙茹
-Antidifferentiation- Chapter 6 朝陽科技大學 資訊管理系 李麗華 教授.
Chapter 10 m-way 搜尋樹與B-Tree
A Search Procedure for Hamilton Paths and Circuits Frank Rubin JACM, Vol. 21, No. 4, pp , Oct
:Commandos ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11463: Commandos 解題者:李重儀 解題日期: 2008 年 8 月 11 日 題意: 題目會給你一個敵營區內總共的建築物數,以及建築物 之間可以互通的路有哪些,並給你起點的建築物和終點.
: Place the Guards ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11080: Place the Guards 解題者:陳盈村 解題日期: 2008 年 3 月 26 日 題意:有一個國王希望在他的城市裡佈置守衛,
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
The Shortest Path Problem
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The distance.
Discrete Mathematics Chapter 4 Induction and Recursion 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)
Copyright © Cengage Learning. All rights reserved.
Trees and Distance. 2.1 Basic properties Acyclic : a graph with no cycle Forest : acyclic graph Tree : connected acyclic graph Leaf : a vertex of degree.
Graph Theory Chapter 7 Eulerian Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)
Graph Theory Chapter 5 Networks 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)
7.1 and 7.2: Spanning Trees. A network is a graph that is connected –The network must be a sub-graph of the original graph (its edges must come from the.
Graph Theory Chapter 6 Matchings and Factorizations 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)
Discrete Mathematics Chapter 2 Basic Structures : Sets, Functions, Sequences, and Sums 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)
Introduction to Algorithms Jiafen Liu Sept
Chapter 3 Trees and Forests 大葉大學 資訊工程系 黃鈴玲
Introduction to Graph Theory
Introduction to Graph Theory
Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.
Chapter 6 Connectivity and Flow 大葉大學 資訊工程系 黃鈴玲
Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供.
Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲.
1 Chapter 15 Graphs, Trees, and Networks. 2 Chap Undirected Graphs 15.2 Directed Graphs 15.3 Trees 15.4 Networks 15.5 Graph Algorithms
6.1.3 Graph representation.
Discrete Mathematics Chapter-8 Graphs 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供.
Trees Thm 2.1. (Cayley 1889) There are nn-2 different labeled trees
Graph Theory Chapter 10 Coloring Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)
Graph Theory Chapter 8 Hamiltonian Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Trees Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering, IIT
大葉大學 資訊工程系 黃鈴玲  G. Agnarsson and R. Greenlaw, Graph Theory: Modeling, Applications, and Algorithms, Pearson,  G. Chartrand and O. R. Oellermann,
Chapter 05 Introduction to Graph And Search Algorithms.
Chapter 7 Planar Graphs 大葉大學 資訊工程系 黃鈴玲  7.2 Planar Embeddings  7.3 Euler’s Formula and Consequences  7.4 Characterization of Planar Graphs.
Trees.
Chapter 10 Independence, Dominance, and Matchings
12. Graphs and Trees 2 Summary
Chapter 13 Graph Algorithms
Trees.
CS 584 Project Write up Poster session for final Due on day of final
Graph Theory: Euler Graphs and Digraphs
6.1.3 Graph representation.
Presentation transcript:

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

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

Copyright  黃鈴玲 Ch 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.

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

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

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).

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

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 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 Let k ← k  1 and go to Step Let k ← k  1 and go to Step 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)

Copyright  黃鈴玲 Ch4-9 Algorithm 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 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. (To find d(u,v) for a fixed vertex u and every vertex v.)

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   v5v5 v6v  2 3 

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

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

Copyright  黃鈴玲 Ch DISTANCE IN WEIGHTED GRAPHS v3v3 v1v1 v6v6 v2v2 h v8v8 v5v5 v4v4 a v7v 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?

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 d(u, v)=10 P: u, x, y, v is a shortest path.

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 目前的距離 )

Copyright  黃鈴玲 Ch4-16 v4v4 v3v3 v1v1 v6v6 v2v2 16 v5v5 u0u0 v7v 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

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)

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

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

Copyright  黃鈴玲 Ch 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

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?

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)} All eccentricities of G 1 : G1:G1: All eccentricities of G 2 : G2:G2:

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.

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.

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.

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

Copyright  黃鈴玲 Ch4-27 Algorithm 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.

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:

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

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