Consolidated search concept introduction

Union query set is a tree-shaped data structure, mainly used to solve some set merge query problems.

The combined search forest refers to storing the data collection in a tree structure, that is, each node stores the corresponding parent node. When the parent node itself means reaching the root node, the root node represents the collection.

#合查集Optimization
There are two optimization methods, namely merging by rank and path compression.
Combine by rank:

将较小的树合并的较大的树上,影响运算时间的树的深度,即此处的秩。

Path compression:

路径压缩即在原来的树的基础上,直接将原来的节点连接到根节点上,从而减少查找根的次数。

But no matter which method is used, the original structure of the tree will be changed and the original structure cannot be protected.

Guess you like

Origin blog.csdn.net/qq_53737964/article/details/112974302