SlideShare a Scribd company logo
1 of 26
Download to read offline
Minimal Spanning Tree



陳鵬宇 (float)
<float.tw@gmail.com>
Rights to Copy
Attribution-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       10



                8
Minimal Spanning Tree
●   最小生成樹
●   邊的權重和最小的生成樹



            5       10



                8
Algorithm
●   Prim's Algorithm
●   Kruskal's Algorithm
Prim Algorithm
●   每次擴張選擇與樹連接的最小權重邊

                        3               B
            A




        5                   6
                                    9

                    8
        C
                7
                                D
Prim Algorithm
●   每次擴張選擇與樹連接的最小權重邊

                        3               B
            A




        5                   6
                                    9

                    8
        C
                7
                                D
Prim Algorithm
●   每次擴張選擇與樹連接的最小權重邊

                        3               B
            A




        5                   6
                                    9

                    8
        C
                7
                                D
Prim Algorithm
●   每次擴張選擇與樹連接的最小權重邊

                        3               B
            A




        5                   6
                                    9

                    8
        C
                7
                                D
Prim Algorithm
●   每次擴張選擇與樹連接的最小權重邊

                        3               B
            A




        5                   6
                                    9

                    8
        C
                7
                                D
Prim Algorithm
●   每次擴張選擇與樹連接的最小權重邊

                        3               B
            A




        5                   6
                                    9

                    8
        C
                7
                                D
Prim Algorithm
●   每次擴張選擇與樹連接的最小權重邊

                        3               B
            A




        5                   6
                                    9

                    8
        C
                7                           Cost 15
                                D
Kruskal's Algorithm
●   兩顆 MST( 把圖切割 ) 要合併時挑選之間最小權
    重邊總是最好的
●   單獨的點可以視為一個 MST
Kruskal's Algorithm
                       3               B
           A




       5                   6
                                   9

                   8
       C
               7
                               D
Kruskal's Algorithm
●   所有邊
                                 3               B
                     A
    –   AB – 3
    –   AC – 5
                 5                   6
    –   AD – 8                               9
    –   BC – 6               8
    –   BD – 9   C
                         7
    –   CD – 7                           D
Kruskal's Algorithm
●   sort
                                 3               B
                     A
    –   AB – 3
    –   AC – 5
                 5                   6
    –   BC – 6                               9
    –   CD – 7               8
    –   AD – 8   C
                         7
    –   BD – 9                           D
Kruskal's Algorithm
●   sort
                                 3               B
                     A
    –   AB – 3
    –   AC – 5
                 5                   6
    –   BC – 6                               9
    –   CD – 7               8
    –   AD – 8   C
                         7
    –   BD – 9                           D
Kruskal's Algorithm
●   sort
                                 3               B
                     A
    –   AB – 3
    –   AC – 5
                 5                   6
    –   BC – 6                               9
    –   CD – 7               8
    –   AD – 8   C
                         7
    –   BD – 9                           D
Kruskal's Algorithm
●   sort
                                 3               B
                     A
    –   AB – 3
    –   AC – 5
                 5                   6
    –   BC – 6                               9
    –   CD – 7               8
    –   AD – 8   C
                         7
    –   BD – 9                           D
Kruskal's Algorithm
●   sort
                                 3               B
                     A
    –   AB – 3
    –   AC – 5
                 5                   6
    –   BC – 6                               9
    –   CD – 7               8
    –   AD – 8   C
                         7
    –   BD – 9                           D
Kruskal's Algorithm
●   sort
                                 3               B
                     A
    –   AB – 3
    –   AC – 5
                 5                   6
    –   BC – 6                               9
    –   CD – 7               8
    –   AD – 8   C
                         7
    –   BD – 9                           D
Note
●   MST 並不唯一
Practice


UVa - 10034
Thank You for Your
          Listening.


102/3/27                   26

More Related Content

Viewers also liked

Lecture 7 transportation problem finding initial basic feasible solution
Lecture 7 transportation problem finding initial basic feasible solutionLecture 7 transportation problem finding initial basic feasible solution
Lecture 7 transportation problem finding initial basic feasible solutionAathi Suku
 
Transportation problem
Transportation problemTransportation problem
Transportation problemShubhagata Roy
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra Sahil Kumar
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Treezhaokatherine
 
Transportation Problem
Transportation ProblemTransportation Problem
Transportation ProblemAlvin Niere
 
Transportation Assignment
Transportation AssignmentTransportation Assignment
Transportation AssignmentNilam Kabra
 

Viewers also liked (8)

Graphs
GraphsGraphs
Graphs
 
Lecture 7 transportation problem finding initial basic feasible solution
Lecture 7 transportation problem finding initial basic feasible solutionLecture 7 transportation problem finding initial basic feasible solution
Lecture 7 transportation problem finding initial basic feasible solution
 
Le protocole stp
Le protocole stpLe protocole stp
Le protocole stp
 
Transportation problem
Transportation problemTransportation problem
Transportation problem
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
Transportation Problem
Transportation ProblemTransportation Problem
Transportation Problem
 
Transportation Assignment
Transportation AssignmentTransportation Assignment
Transportation Assignment
 

More from 陳 鵬宇

[ACM-ICPC] Matching
[ACM-ICPC] Matching[ACM-ICPC] Matching
[ACM-ICPC] Matching陳 鵬宇
 
[ACM-ICPC] Backtracking
[ACM-ICPC] Backtracking[ACM-ICPC] Backtracking
[ACM-ICPC] Backtracking陳 鵬宇
 
[ACM-ICPC] Binary Search
[ACM-ICPC] Binary Search[ACM-ICPC] Binary Search
[ACM-ICPC] Binary Search陳 鵬宇
 
[ACM-ICPC] Greedy Algorithm
[ACM-ICPC] Greedy Algorithm[ACM-ICPC] Greedy Algorithm
[ACM-ICPC] Greedy Algorithm陳 鵬宇
 
Boot to Gecko Introduction
Boot to Gecko IntroductionBoot to Gecko Introduction
Boot to Gecko Introduction陳 鵬宇
 

More from 陳 鵬宇 (6)

[ACM-ICPC] Matching
[ACM-ICPC] Matching[ACM-ICPC] Matching
[ACM-ICPC] Matching
 
Git
GitGit
Git
 
[ACM-ICPC] Backtracking
[ACM-ICPC] Backtracking[ACM-ICPC] Backtracking
[ACM-ICPC] Backtracking
 
[ACM-ICPC] Binary Search
[ACM-ICPC] Binary Search[ACM-ICPC] Binary Search
[ACM-ICPC] Binary Search
 
[ACM-ICPC] Greedy Algorithm
[ACM-ICPC] Greedy Algorithm[ACM-ICPC] Greedy Algorithm
[ACM-ICPC] Greedy Algorithm
 
Boot to Gecko Introduction
Boot to Gecko IntroductionBoot to Gecko Introduction
Boot to Gecko Introduction
 

[ACM-ICPC] Minimal Spanning Tree

  • 1. Minimal Spanning Tree 陳鵬宇 (float) <float.tw@gmail.com>
  • 2. Rights to Copy Attribution-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
  • 3. Spanning Tree ● 生成樹 ● 從圖中分離出一顆樹包含圖中所有點
  • 4. Spanning Tree ● 生成樹 ● 從圖中分離出一顆樹包含圖中所有點
  • 5. Minimal Spanning Tree ● 最小生成樹 ● 邊的權重和最小的生成樹 5 10 8
  • 6. Minimal Spanning Tree ● 最小生成樹 ● 邊的權重和最小的生成樹 5 10 8
  • 7. Algorithm ● Prim's Algorithm ● Kruskal's Algorithm
  • 8. Prim Algorithm ● 每次擴張選擇與樹連接的最小權重邊 3 B A 5 6 9 8 C 7 D
  • 9. Prim Algorithm ● 每次擴張選擇與樹連接的最小權重邊 3 B A 5 6 9 8 C 7 D
  • 10. Prim Algorithm ● 每次擴張選擇與樹連接的最小權重邊 3 B A 5 6 9 8 C 7 D
  • 11. Prim Algorithm ● 每次擴張選擇與樹連接的最小權重邊 3 B A 5 6 9 8 C 7 D
  • 12. Prim Algorithm ● 每次擴張選擇與樹連接的最小權重邊 3 B A 5 6 9 8 C 7 D
  • 13. Prim Algorithm ● 每次擴張選擇與樹連接的最小權重邊 3 B A 5 6 9 8 C 7 D
  • 14. Prim Algorithm ● 每次擴張選擇與樹連接的最小權重邊 3 B A 5 6 9 8 C 7 Cost 15 D
  • 15. Kruskal's Algorithm ● 兩顆 MST( 把圖切割 ) 要合併時挑選之間最小權 重邊總是最好的 ● 單獨的點可以視為一個 MST
  • 16. Kruskal's Algorithm 3 B A 5 6 9 8 C 7 D
  • 17. Kruskal's Algorithm ● 所有邊 3 B A – AB – 3 – AC – 5 5 6 – AD – 8 9 – BC – 6 8 – BD – 9 C 7 – CD – 7 D
  • 18. Kruskal's Algorithm ● sort 3 B A – AB – 3 – AC – 5 5 6 – BC – 6 9 – CD – 7 8 – AD – 8 C 7 – BD – 9 D
  • 19. Kruskal's Algorithm ● sort 3 B A – AB – 3 – AC – 5 5 6 – BC – 6 9 – CD – 7 8 – AD – 8 C 7 – BD – 9 D
  • 20. Kruskal's Algorithm ● sort 3 B A – AB – 3 – AC – 5 5 6 – BC – 6 9 – CD – 7 8 – AD – 8 C 7 – BD – 9 D
  • 21. Kruskal's Algorithm ● sort 3 B A – AB – 3 – AC – 5 5 6 – BC – 6 9 – CD – 7 8 – AD – 8 C 7 – BD – 9 D
  • 22. Kruskal's Algorithm ● sort 3 B A – AB – 3 – AC – 5 5 6 – BC – 6 9 – CD – 7 8 – AD – 8 C 7 – BD – 9 D
  • 23. Kruskal's Algorithm ● sort 3 B A – AB – 3 – AC – 5 5 6 – BC – 6 9 – CD – 7 8 – AD – 8 C 7 – BD – 9 D
  • 24. Note ● MST 並不唯一
  • 26. Thank You for Your Listening. 102/3/27 26