Questions tagged [union-find]

A union/find data structure is a data structure used for maintaining a partition of a set.

184 questions
3
votes
1 answer

Finding connected components in a DYNAMIC Graph

When it comes to finding connected components in a graph we can use DFS or DSU. Does there exist an algorithm which is stable to a changing graph, where node can be added, edge can be removed, node can be removed. Eg. If we add a node to a graph and…
3
votes
3 answers

Do the order of edges matter in union find?

I am learning union-find and to understand it better, I have written a small program: #include #include #include using namespace std; vector parent, sz; int find(int i) { if(parent[i]==i) return i; …
Someone
  • 611
  • 4
  • 13
3
votes
2 answers

How to implement a union-find (disjoint set) data structure in Coq?

I am quite new to Coq, but for my project I have to use a union-find data structure in Coq. Are there any implementations of the union-find (disjoint set) data structure in Coq? If not, can someone provide an implementation or some ideas? It doesn't…
Alex
  • 2,915
  • 5
  • 28
  • 38
3
votes
2 answers

Dynamic union find algorithm in Prolog

Lets assume I have sets S1,..,Sn and we want to find smallest covers C1,..,Cm so that in each cover there are never disjoint connected components. for example with the sets S1=[X,Y], S2=[Y,Z], S3=[T] I would find the covers C1=[X,Y,Z] and C2=[T].…
user502187
3
votes
2 answers

Iterating over classes in a disjoint set data structure

I've implemented a disjoint set data structure for my program and I realized I need to iterate over all equivalence classes. Searching the web, I didn't find any useful information on the best way to implement that or how it influences complexity.…
3
votes
0 answers

Is there a DB system which supports Union-Find (Disjoint Sets) data structure

Basically looking for a DB which supports this data structure OOTB
user976850
  • 1,086
  • 3
  • 13
  • 25
3
votes
2 answers

Weighted quick-union with path compression algorithm: time complexity analysis

I'm learning "Weighted quick-union with path compression" algorithm for an union/find structure. The Princeton edu site explained detailedly the algorithm. And here is the implementation in Java: public class WQUPC { private int[] id; private…
3
votes
1 answer

Optimization for Find All Weakly Connected Components in Directed Graph Using Quick-Find Algorithm (Java)

I'm seeking to improve my solution to find all weakly connected components in a directed graph using Quick-Find algorithm. Problem Statement Given a list of DirectedGraphNode, find all islands (i.e weakly connected components). public class…
gyoho
  • 799
  • 2
  • 9
  • 25
3
votes
1 answer

c++ free(): invalid pointer error while path compression (union by rank)

I looked through other similar questions but couldn't figure out the reason for this error. I'm writing a C++ program to implement Kruskal's Minimum Spanning Tree algorithm using Union by rank with path compression. It prints the edges of the MST…
kabir
  • 145
  • 1
  • 6
3
votes
2 answers

Can recursive union find be optimized?

When implementing union-find, I would usually write the find function with path compression like this: def find(x): if x != par[x]: par[x] = find(par[x]) return par[x] This is easy to remember and arguably easy to read. This is also…
Thomas Ahle
  • 30,774
  • 21
  • 92
  • 114
3
votes
1 answer

MinHashing vs SimHashing

Suppose I have five sets I'd like to cluster. I understand that the SimHashing technique described here: https://moultano.wordpress.com/2010/01/21/simple-simhashing-3kbzhsxyg4467-6/ could yield three clusters ({A}, {B,C,D} and {E}), for instance, if…
cjauvin
  • 3,433
  • 4
  • 29
  • 38
3
votes
2 answers

Detect cycle in a graph using Kruskal's algorithm

I'm implementing Kruskal's algorithm, which is a well-known approach to finding the minimum spanning tree of a weighted graph. However, I am adapting it to find cycles in a graph. This is the pseudocode for Kruskal's algorithm: KRUSKAL(G): 1 A = ∅ 2…
Abhinav Gauniyal
  • 7,034
  • 7
  • 50
  • 93
3
votes
2 answers

Weighted union rule

Can someone check with me if I'm using the rule right in the last step (7)? UPDATE: Numbers inside the parentheses are the number of elements (weight(?)) of each set that takes part in the Union. Uppercase letters are names of sets. As I understand…
user2692669
  • 461
  • 8
  • 23
3
votes
1 answer

Analyzing Time complexity of union-find Algorithm?

Please give a brief and simple approach to analyzing time complexity of the union-find algo. In the two cases 1. Standard Approach 2. Weighted-union heuristic Approach I know in the standard version its time complexity is: O(n^2) and in case of…
Sonali
  • 631
  • 3
  • 9
  • 11
3
votes
1 answer

Unification algorithm example in WAM (Warren's Abstract Machine)

Exercise 2.2 in Warren's Abstract Machine: A Tutorial Reconstruction asks for representations for the terms f(X, g(X, a)) and f(b, Y) and then to perform unification on the address of these terms (denoted a1 and a2 respectively). I've constructed…
1 2
3
12 13