DataStructure Minimum Spanning Tree
Minimum Spanning Tree
Characteristics
- A tree
- We can regard a tree as a special graph
- No loop
- |V| - 1 edges with |V| vertexes
- We can regard a tree as a special graph
- Spanning
- Include all nodes in this tree
- |V| - 1 edges are in the graph
- Minimum
- The weighted sum is minimum
If there exists a minimum spanning tree, the graph must be connected.
Greedy Algorithm
- Every step should be the optimal!
- Optimal means that the weight should be as little as possible
- Restrictions
- Only use the edges in the graph
- Use |V| - 1 edges
- No loop
Prim Algorithm - Grow A Tree!
This algorithm is very similar to Dijkstra algorithm. It is suitable for dense graph.
1 | void Prim(){ |
Kruskal Algorithm - Combine Trees to A Forest!
1 | void Krustal(){ |