最小生成树
Prim Algorithm
How does it run?
- Choose an arbitrary vertex and let
- Choose a vertex closest to and add it into and record the corresponding edge
- go on until all vertices are in
- The recorded edges and constructs a Minimum Spanning Tree
Let be a weithted connected graph and has vertices.
is a tree built through Prim Algorithm.
Show is a minimum spanning tree:
First, there must be an optimal solution which contains the edge with the minimal weight.
If not, we can add this edge into the solution and obtain a cycle, then remove an edge with larger weight and we can obtain a better solution.
Recursively, if are in a part of some optimal solution, then is also in it.
Kruskal Algorithm
The main idea of Kruskal Algorithm is linking different connected components continuously with the edge with minimal weight, until there is only one connected componen remains.
Procedure:
- Each vertex constructs a single connected component
- linking
- finish
Rightness:
Denote the result of Kruskal Algorithm by and the Minimal Spanning Tree by
Add into and it leads to a cycle including some of
Remove the most weighted edge in this cycle and belonging to
Then obtain a new spanning tree
Edge and edge must have the same weight
- Since is the minimum spanning tree,
- Since is not in , according to the rule of Kruskal Algorithm, there are 2 cases:
- Leads to cycle with vertices added already (since has the minimal weight in s, those vertices should be the common vertices of and ), but is impossible because is exactly in
- or the second case, the weight of is no less than and would be considered after
- Then it’s clear,
And is also a minimum spanning tree
Following this way, we can convert into with keeping its weight
Hence is also a minimum spanning tree
Intresting
MST is the short of “Minimum Spanning Tree”.
Why not “Minimal Spanning Tree”?
One kind of explanation:
- minimum is a quantitative representation of the smallest amount needed
- minimal is a is a qualitative characteristic