Preface
This blog introduces and queries the set and the Minimum Spanning Tree of the graph. For the query set, we introduce its basic concepts, analyze its complexity, and finally use the query set to analyze the Minimum Spanning Tree.
And query the reference documents 《 Algorithm Introduction: Blog: http://blog.csdn.net/dm_vincent/article/details/7655764. The query set includes three operations: make_set, find_set, and union_set. Linked List representation: each node includes a value and two pointers: one pointing to the next node, one pointing to the header node, and one head and one tail. Each set represents a header node, therefore, each node has to point to the header node, so that you can quickly locate the header node. Complexity:
The root of the tree indicates that two optimizations can be introduced, which are merged by rank and compressed by path. When this optimization is used at the same time, the worst run time is: O (M *α (N)), M is the total number of operations,α (n) is a growth and slow function, usuallyα (n) <= 4; therefore, the complexity of the worst case can be regarded as linear;
Minimum Graph Generation tree
As a complex data structure, a graph is a simple example of graph traversal. Next, we will briefly introduce the Minimum Spanning Tree.
Related Concepts:
Connected Graph: For an undirected graph, if there is a path between any two vertices, the undirected graph is connected;
Strongly Connected Graph: For a directed graph, if any two vertices in the graph have a directed path, the directed graph is strongly connected;
Connected Component: each connected subgraph in a non-connected graph is the connected component of the graph.
To solve the problem of least spanning tree, we use greedy ideas, query sets, and recursion.
Kruskal + and query set implementation:
# include
# include
# include
# include
# define bug puts ("here !!! "); Using namespace STD; const int n = 5005; int pre [N]; // space complexity int n, m; struct node {int U, V; int W ;} E [N]; bool CMP (const node A, const Node B) {return. W
N, N) {CIN> m; For (INT I = 0; I
E [I]. u> E [I]. v> E [I]. W ;}kruskal () ;}
Kruskal is an edge-based search. You must first sort the edge and view the current optimal and greedy idea each time.
Prim algorithm: Click to open the link