Minimum Spanning Tree Learning

Source: Internet
Author: User

Overview:

In a given undirected graph G = (V, E), (u, v) represents the edge connecting the vertex u and the vertex v (I .e.), while w (u, v) indicates the weight of the edge. If T is a subset of E (that is, a non-circular graph, and w (T) is the smallest, T is the smallest Spanning Tree of G.

The Minimum Spanning Tree is short for the minimum weight spanning tree.

Minimum Spanning Tree:

In an undirected connected graph G = (V, E), the minimum spanning tree is the edge weight of all vertices and the minimum subgraph T, T has no loop and connects all vertices, so it must be a tree.

Application:

Network G represents the road network lines of communication lines between n cities (vertex represents the city, edge represents the communication lines between the two cities, and the weight on the edge represents the length or cost of the line ). The optimal solution for solving the communication line or the minimum total cost can be achieved by finding the Minimum Spanning Tree of the network.

How can we find the Minimum Spanning Tree?

One is the Kruskal algorithm, and the other is the Prim algorithm, both of which use greedy policies.

Several Concepts involved:

Secure edge: A is the subset of A minimum spanning tree of G. If AU {(u, v)} is still the subset of A minimum spanning tree of G, then (u, v) is the security side;

Cut: a division of V by undirected graph G = (V, E) (S, V-S );

Side (u, v) by cutting (S, V-S) :( u, v) one vertex is located in S and the other vertex is located in V-S;

Cut without prejudice to A: No side in A passes this cut;

Light edge: the edge with the smallest weight in all edges that are cut (multiple edges may exist ).

Pseudocode generated by the minimal spanning tree:

GENERIC-MST (G, w) A = empty set while A does not form a spanning tree (if A cannot form A spanning tree) do find an edge (u, v) that is safe for A (find the security side of A) A = AU {(u, v)} return


Introduction theorem of algorithms:

G = (V, E) is a undirected connected weighted graph. A is A subset of E, which is contained in A minimum spanning tree of G. Set cut (S, V-S) is G of any one without prejudice A cut (that is to say A of any side of the two endpoints either all in S, or all in V-S ), the side (u, v) is a light side by cutting (S, V-s) (that is

(U, v) is the smallest weight of all edges distributed in S and V-S), then (u, v) is safe for set.

Inference:

A is A subset of A minimum spanning tree of G = (V, E. G (A) = (V, A) is A forest in Figure G (only the edge in A set), C = (Vc, Ec) is G () (tree in the forest ). If the edge (u, v) is A light edge connecting one of the other connected branches in C and G (A), then (u, v) is safe for set.

Pseudo-code implementation:

Kruskal Algorithm

MST-KRUSKAL (G, w) A = empty set for each vertex v ε V [G] do MAKE_SET (v) sort the edges of E into nondescreasing order by weight w for each edge (u, v) ε E, take in nondescreasing order by weight do if FIND-SET (u )! = FIND-SET (v) // If u and v are not in the same connected branch, add (u, v, it is inferred that this side is safe then A = AU {(u, v)} UNION (u, v) return


(FIND-SET (u) is to FIND the connected branch of u. Kruskal finds the edge with the smallest weight in the world, then checks whether the edge is "valid", and makes a trade-off until all edges are traversed. The running time of the Kruskal algorithm is O (ElgV ).) 

Prim algorithm (Prim is suitable for dense graphs. It is not suitable for the problem of finding the Minimum Spanning Tree Based on given coordinates .)

MST-PRIM (G, w, r) for each u ε V [G] do key [u] = ∞ π (u) = NIL // π (u) yesu's front key [r] = 0 Q = V [G] while Q! = Empty set do u = EXTRACT-MIN (Q) for each v ε Adj [u] do if v ε Q and w (u, v)
 
  
(Q is a priority queue, and key [v] is the minimum weight of all edges that connect v to a vertex in the tree. If such an edge does not exist, then k [v] = ∞. The Prim algorithm looks for an edge with a small weight in the local area (this edge must be valid) until all nodes are traversed. The running time of the Prim algorithm is O (ElgV), which is approximately the same as that of the Kruskal algorithm. The Prim algorithm uses the same policy as the Dijkstra algorithm. It maintains an array key of weights and is constantly updated during iteration .)

-------------------------------------------------------

Code:

Add ................

Bytes ----------------------------------------------------------------------------------------------

Source: Click to open the link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.