Disjoint-set (disjoint set) Remove operation

Add to disjoint-set (disjoint sets) of a R e m O v e ( X ) Remove(X) operation that the X X is removed from the current collection and put it in his collection.

Realize ideas

English Haraku

We assume that the tree is implemented with pointers instead of a simple array. Thus Find will return a pointer instead of an actual set name. We will keep an array to map set numbers to their tree nodes. Union and Find are implemented in the standard manner. To perform R e m O v e ( X ) Remove(X) , first perform a F i n d ( X ) Find(X) with path compression. Then mark the node containing X X as vacant. Create a new one-node tree with X X and have it pointed to by the appropriate array entry. The time to perform a Remove is the same as the time to perform a Find, except that there potentially could be a large number of vacant nodes. To take care of this, after N N Removes are performed, perform a Find on every node, with path compression. If a F i n d ( X ) Find(X) returns a vacant root, then place X X in the root node, and make the old node containing X X vacant. The results of guarantee that this will take linear time, which can be charged to the N N Removes. At this point, all vacant nodes (indeed all nonroot nodes) are children of a root, and vacant nodes can be disposed (if an array of pointers to them has been kept). This also guarantees that there are never more than 2 N 2N nodes in the forest and preserves the M a ( M , N ) Mα (M, N) asymptotic time bound.

Baidu translator

We assume that the tree is a pointer to achieve, rather than a simple array. therefore F i n d Find returns a pointer instead of the actual set name. We will retain an array to be mapped to their set number of tree nodes. The n i O n Union and F i n d Find in the standard manner. To perform R e m O v e X Remove(X) , compression is first performed using the path F i n d X Find(X) . Then will contain X X node as empty. use X X to create a new single-node tree, and point to it with an appropriate array of items. Find the same time removing the execution time and execution, but there may be a large number of idle nodes. To solve this problem, in execution N N After a remove, executed on each node a F i n d Find , andpath compression. in case F i n d X Find(X) returns an empty root, then X X in the root node, and comprising X X old node becomes empty node. The results ensure that this will take linear time, which will be counted N N number removed. In this case, all the child nodes empty node (virtually all non-root node) is the root, may release an empty node (leave the array pointers to them). This also ensures that the forest does not exceed 2 N 2N nodes, and maintain M a M N Mα (M, N) asymptotically bounded time.

Published 32 original articles · won praise 18 · views 3233

Guess you like

Origin blog.csdn.net/u011714517/article/details/104170689