What are the common operations of C++ and checking collections?
This article mainly introduces the relevant knowledge of the common operation of C++ and search collection, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe that after reading this C++ and searching the common operation of what articles will have a harvest, let's take a look.
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)