Connected undirected graph g= (v,e), for each edge is given a weight w, want to find the edge of the collection is all points can be connected, and the weight of these edges can be minimized.
Because these edges are ring-free and can connect all the nodes, it eventually makes up a tree. This tree of Figure G is called the spanning tree, and the problem of finding the tree is called the minimum spanning tree problem.
What you need to learn here is the Kruskal algorithm and the prim algorithm.
Both of these algorithms are greedy algorithms, each of which must choose one of several possible choices.
This strategy does not necessarily find a spanning tree with the least weight.
The greedy algorithm grows one edge of the smallest spanning tree at all times and, throughout the implementation of the strategy, manages a set a that follows the following cyclic invariant:
Before each cycle, a is a subset of the smallest spanning tree in a section.
Before each step, an edge that is not part of collection A is selected to be added to the collection A, so that a new collection of a and that edge is still a subset of the smallest spanning tree.
The addition of this side to a does not destroy the cyclic invariant of a, so it is also called a secure edge.
Here's how to find the rules for identifying secure edges and build a minimum spanning tree algorithm using this rule.
Secure Edge Identification rules
Kruskal algorithm
Prim algorithm
Graph algorithm the best niche into a tree