1 / 21

Graph Theory

Graph Theory. Chapter 13 Graph Algorithms. 大葉大學 資訊工程系 黃鈴玲 2011.10. Contents. 13.4 Breadth-First Search 13.5 Depth-First Search 13.6 Connected Components 13.7 Dijkstra’s Shortest Path Algorithm. 13.4 Breadth-First Search. 先進先出.

Download Presentation

Graph Theory

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 Theory Chapter 13 Graph Algorithms 大葉大學 資訊工程系 黃鈴玲 2011.10

  2. Contents • 13.4 Breadth-First Search • 13.5 Depth-First Search • 13.6 Connected Components • 13.7 Dijkstra’s Shortest Path Algorithm

  3. 13.4 Breadth-First Search 先進先出 Three operations: (1) Enqueue(Q, u): adds u to the tail of Q.(2) Dequeue(Q): removes one item from the head of the nonempty queue Q and returns that element.(3) Empty(Q): returns True if Q is empty, False otherwise.

  4. // 每次mark一點就把 i + 1 若G不是connected,要執行到所有點都mark為止。

  5. Example 13.5 T1 T2 T3 T4 T5 s    y=6   1 6 Q: 8 5 9 x=1

  6. source     2 7 4 3

  7. G v5 v13 v8 v2 v12 v7 v6 v1 v10 v15 v14 v4 v9 v3 v11 Ex: Find a BFS forest for the following graph G with source v1. (下標小的優先選)

  8. 13.5 Depth-First Search

  9. G v5 v13 v8 v2 v12 v7 v6 v1 v10 v15 v14 v4 v9 v3 v11 Ex: Find a DFS forest for the following graph G with source v1. (下標小的優先選)

  10. 13.6 Connected Components Component number 1 2 用DFS拜訪所有點 3 4 4 1 3 2 2 4 1 1 4 2 1 2 1

  11. 13.7 Dijkstra’s Shortest Path algorithm 加Father[.] of size n: 記錄shortest path的上一點 Father[i] =1 if W1i Father[u] =v if pathcost[u] = pathcost[v] +Wuv

  12. Father[3] =1 第1個for迴圈 source Father[4] =1 Umin={3}

  13. 第2個for迴圈 Father[3] =1 Father[2] =3 i=1 source Father[5] =3 Father[6] =3 Father[4] =3 Umin={4}

  14. Father[3] =1 Father[2] =3 i=2 source Father[5] =4 Father[6] =3 Father[4] =3 Umin={5}

  15. Father[3] =1 Father[2] =3 i=3 source Father[5] =4 Father[6] =5 Father[4] =3 Umin={2}

  16. Father[3] =1 Father[2] =3 i=4 source Father[5] =4 Father[6] =2 Father[4] =3 end

  17. Sourceu0 minimum pathcost father v2 v3 v4 v5 v6 v7 U v1 (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (18, v5) (, -) (, -) (, -) (, -) (, -) (, -) (, -) (, -) Ex 8 v1 16 v5 10 13 v7 v6 9 11 7 17 v2 6 v4 14 5 v3 {v1,…,v7} (13, u0) (16, u0) (8, u0) {v1,…,v7}-v5 {v1,v3,v4,v6,v7} (18, v5) (13, u0) (25, v5) (15, v5) {v1,v3,v6,v7} (25, v5) (15, v5) {v3,v6,v7} (18, v5) (20, v4) {v6,v7} (20, v4) v5, v4 u0, Shortest u0-v3path:

  18. Ex: Find the distances from 1 to x for each x=2, 3,…,8, and determine their shortest paths. 2 5 4 1 2 2 3 1 3 1 5 2 4 5 3 5

More Related