C++ and check how to achieve it.
This article mainly introduces "how to realize C++ and search collection". In daily operation, I believe many people have doubts about how to realize C++ and search collection. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve C++ and search collection". Next, please follow the editor to study!
And lookup set is a kind of tree data structure, which is used to deal with some merge and query problems of non-additive sets. It is often expressed as a forest in use. And lookup sets are also used to maintain collections, and unlike set learned earlier, lookup sets can easily maintain many collections at the same time. It will be very troublesome to use set for maintenance. The core idea of the search set is to record which node the father node of each node is.
Preface
The parallel lookup set is a kind of multi-tree, which is used to deal with the merge and query of disjoint sets.
Popular understanding: in daily life, we will give accommodation and favouritism because someone is our own friend, even if a friend of a friend has a friend. The basic concept of parallel search set is to judge whether two sets are "friends" and make the two sets "friends".
Common operation
Initialization: each node acts as a separate collection
Query: find the representative element of the collection in which the element is located, that is, the root node
Merge: merge the collection of two elements into one collection
Before merging, you should first judge whether two elements belong to the same set, and use the "query" above to implement
Algorithm realization
Initialization: initially, each node is a collection, and father [I] represents the parent node of node I. if father [I] = I, we think this node is the root node of the current collection (at the beginning, the root node of each node is himself).
Void init () {for (int I = 1; I)