Download - [ACM-ICPC] Minimal Spanning Tree
Minimal Spanning Tree
陳鵬宇 (float)<[email protected]>
Rights to CopyAttribution-ShareAlike 3.0
You are free:
– to Share — to copy, distribute and transmit the work
– to Remix — to adapt the work
– to make commercial use of the work
● Under the following conditions:
– Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
– Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
– License text: http://creativecommons.org/licenses/by-sa/3.0/legalcode
Spanning Tree● 生成樹● 從圖中分離出一顆樹包含圖中所有點
Spanning Tree● 生成樹● 從圖中分離出一顆樹包含圖中所有點
Minimal Spanning Tree● 最小生成樹● 邊的權重和最小的生成樹
5
8
10
Minimal Spanning Tree● 最小生成樹● 邊的權重和最小的生成樹
5
8
10
Algorithm● Prim's Algorithm● Kruskal's Algorithm
Prim Algorithm● 每次擴張選擇與樹連接的最小權重邊
A
D
B
C
5
3
7
9
6
8
Prim Algorithm● 每次擴張選擇與樹連接的最小權重邊
A
D
B
C
5
3
7
9
6
8
Prim Algorithm● 每次擴張選擇與樹連接的最小權重邊
A
D
B
C
5
3
7
9
6
8
Prim Algorithm● 每次擴張選擇與樹連接的最小權重邊
A
D
B
C
5
3
7
9
6
8
Prim Algorithm● 每次擴張選擇與樹連接的最小權重邊
A
D
B
C
5
3
7
9
6
8
Prim Algorithm● 每次擴張選擇與樹連接的最小權重邊
A
D
B
C
5
3
7
9
6
8
Prim Algorithm● 每次擴張選擇與樹連接的最小權重邊
A
D
B
C
5
3
7
9
6
8
Cost 15
Kruskal's Algorithm● 兩顆 MST( 把圖切割 ) 要合併時挑選之間最小權
重邊總是最好的● 單獨的點可以視為一個 MST
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
● 所有邊– AB – 3– AC – 5– AD – 8– BC – 6– BD – 9– CD – 7
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
● sort– AB – 3– AC – 5– BC – 6– CD – 7– AD – 8– BD – 9
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
● sort– AB – 3– AC – 5– BC – 6– CD – 7– AD – 8– BD – 9
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
● sort– AB – 3– AC – 5– BC – 6– CD – 7– AD – 8– BD – 9
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
● sort– AB – 3– AC – 5– BC – 6– CD – 7– AD – 8– BD – 9
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
● sort– AB – 3– AC – 5– BC – 6– CD – 7– AD – 8– BD – 9
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
● sort– AB – 3– AC – 5– BC – 6– CD – 7– AD – 8– BD – 9
Kruskal's Algorithm
A
D
B
C
5
3
7
9
6
8
Note● MST 並不唯一
Practice
UVa - 10034
102/3/27 26
Thank You for Your Listening.