简体   繁体   English

支持删除的不相交集数据结构

[英]Disjoint set data structure supporting deletion

Assume that we have a set of n disjoint nodes {node 1 ,node 1 ,...,node n } 假设我们有一组n个不相交的节点{节点1 ,节点1 ,...,节点n }

What is the fastest data structure and algorithm for the following 3 operations: 以下3个操作的最快数据结构和算法是什么:

  1. Union(x,y): add an un-directed edge between node x and node y , there can be at most one edge between two nodes. Union(x,y):在节点x和节点y之间添加无方向边,两个节点之间最多可以有一条边。

  2. IsConnected(x,y): returns true if node x and node y are connected directly or indirectly, ie node x and node y are in the the same connected component. IsConnected(x,y):如果节点x和节点y直接或间接连接,则返回true,即节点x和节点y在同一个连接组件中。

  3. Un-union(x,y): remove the edge between node x and node y if it exists. Un-union(x,y):删除节点x和节点y之间的边(如果存在)。

Disjoint-set is a perfect data structure for the first two operations, but it cannot support the 3rd operation directly. Disjoint-set是前两个操作的完美数据结构,但它不能直接支持第3个操作。 What is the alternative? 有什么选择?

If we simulate the process, the first and 3rd operations can be implemented in O(1) but 2nd operation is O(n), so I would like to see if it is possible to make all three operations run in O(logn) time or less. 如果我们模拟过程,第一个和第三个操作可以在O(1)中实现,但第二个操作是O(n),所以我想看看是否可以在O(logn)时间内运行所有三个操作或更少。

Link/cut tree may perform these 3 operations in O(log N) time. 链接/剪切树可以在O(log N)时间内执行这3个操作。

You can read about Link/cut tree and related data structures in this book: "Handbook of Data Structures and Applications" (Chapter 35). 您可以在本书中阅读“链接/剪切树”和相关数据结构: “数据结构和应用手册” (第35章)。

Link/cut tree does not allow adding an edge between nodes, that are already (indirectly) connected. 链接/剪切树不允许在已经(间接)连接的节点之间添加边缘。 If you need "Union(x,y)" operation to support this, the problem becomes more complicated, and you can solve it as dynamic connectivity problem in undirected graphs. 如果您需要“Union(x,y)”操作来支持此操作,则问题会变得更加复杂,您可以将其解决为无向图中的动态连接问题。 (See chapter 36.4 in the same book or this pdf ). (参见同一本书或本pdf中的第36.4章)。 In this case insertion/deletion complexity increases to O(log 2 N). 在这种情况下,插入/删除复杂性增加到O(log 2 N)。

Kaplan, Shafrir and Tarjan propose a general technique to add deletion to union-find data structures by incremental rebuilding and show deletion takes O(t_f(n) + t_i(n)) which are the costs for finding and inserting a node, respectively. Kaplan,Shafrir和Tarjan提出了一种通过增量重建向联合查找数据结构添加删除的一般技术,并且显示删除分别采用O(t_f(n)+ t_i(n)),这是寻找和插入节点的成本。 The general idea is keeping the number of deleted items in each set and rebuilding the set when this number reaches a certain threshold. 一般的想法是在每个集合中保留已删除项目的数量,并在此数量达到特定阈值时重建集合。

Alstrup ,Gørtz , Rauhe, Thorup and Zwick show how to implement deletions in constant time by noting which elements in a tree are occupied and which are vacant and "tidying up" the tree after delete operations. Alstrup,Gørtz,Rauhe,Thorup和Zwick通过指出树中的哪些元素被占用以及哪些是空的并且在删除操作之后“整理”树来显示如何在恒定时间内实现删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM