Whats the best algorithm for Non Disjoint Set Union?

…衆ロ難τιáo~ 提交于 2021-02-08 03:31:28

问题


Lets say there are two (non disjoint) sets of points (cartesian space), what is the best case complexity algorithm to perform the union of the two sets ?


回答1:


Since the point coordinates are arbitrary and there is no special relation between them, I don't see this problem as a geometric specific problem. It is the generic problem of efficiently merging S1 and S2 into a new set S.

I know about two options:

1) When the sets are stored in a hash table (actually a hash set), the union takes O(|S1|+|S2|) in average.

2) If you store the structures in a balanced search tree, you can achieve a worst case time of O(|S1| * Log(|S1|)), assuming that |S1|>|S2|.




回答2:


Actually, if the sets are in a balanced search tree, I think you can do it in O(|S2| (1+log (|S1|/|S2|)), where |S1|>=|S2|. This is optimal in the worst case.



来源:https://stackoverflow.com/questions/3708070/whats-the-best-algorithm-for-non-disjoint-set-union

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!