A union/find data structure is a data structure used for maintaining a partition of a set.
Questions tagged [union-find]
184 questions
0
votes
0 answers
time complexity for naive quick union algorithm
how can I calculate the worst case of quick-union algorithm.
Actually, I am always struggled in time complexity when tree height is involved in. I know it is related to O(h), However the tree is developing in the code.
So what should be the correct…

nathan
- 754
- 1
- 10
- 24
0
votes
3 answers
Understanding union find
I read the wiki page and don't understand why it matters to append a smaller list to a larger one.
Here is that part of the algorithm from the wiki page:
Suppose you have a collection of lists and each node of each list
contains an object, the…

Maksim Dmitriev
- 5,985
- 12
- 73
- 138
0
votes
2 answers
How can we choose which element to be representative in a Union-find data structure?
When we merge two sets for example A={1,2,3} and B={6,7,8},let 1,8 be the representatives of both the sets respectively,now if we merge both the sets
what will be the representative of the resultant set? can we choose based on our choice ?
In my…
0
votes
1 answer
Wrong answer while calculating Minimum Spanning Tree Using Kruskal Algorithm
I am Trying to solve this MST question on spoj using kruskal algorithm. my program seems to work on all test cases but spoj repeatedly is giving WA on this code.
I am not able to find any failing test cases on this code. Can someone please point out…

sjsupersumit
- 154
- 2
- 11
0
votes
1 answer
Union-Find operations on a tree?
can someone please explain the answer in bold? How it's done?
Below is a sequence of four Union-Find operations (with weighted-union and full com-
pression) that led to the following up-tree. What were the last two operations?
Answer: Union(D,A),…

Square-root
- 853
- 1
- 12
- 25
0
votes
1 answer
What is importance of 'rank' in union by rank and path compression algorithm?
I have an understanding of the algorithm in this way...
path compression helps lower time for find operation and overtime the time complexity for path compression averages out to be O(1).
we decide which of the two is a parent node (during union…

95_96
- 341
- 2
- 12
0
votes
0 answers
Finding connected component in undirected graph with union-find algorithm gives wrong answer
I'm using union-find algorithm to find all the connected components of an un-directed graph. For some unknown reasons it gives a wrong answer. The input graph that I give is connected and yet it outputs 2 different labels for that graph.
I would be…

user3811219
- 93
- 1
- 8
0
votes
2 answers
Union find in python3
I know how to implement union find in general, but I was thinking of whether there would be a way to utilize the set structure in python to achieve the same result.
For example, we can union sets pretty easily. But I'm not sure how to determine if…

Lana
- 1,124
- 1
- 8
- 17
0
votes
1 answer
What is the algorithm to get disjoint set from edgelist with weights
I have a list of edges with weights and I want to get the disjoint set from them. However, I want to track the weights also in the set. e.g If I have a dataset,
N1 N2 Weight
a1 a2 1.0
a2 a3 0.5
a3 a5 1.0
a4 a8 1.0
a8 a9 0.8
It will result in two…

DonDyck
- 1,451
- 5
- 20
- 35
0
votes
1 answer
Union-Find using Hashmap in Java
I am working on a union-find algorithm, using the following :
HashMap parent = new HashMap();
I have written this method to find the last member of a family
public E find(E src)
{
while (parent.get(src) != null)
…

colonelmoutarde
- 25
- 4
0
votes
0 answers
Testing a 2d Array for Percolation (union find)
I have a 2d array created of size n that holds 1s and 0s representing closed and open spaces respectively.
Now I need to test the 2d array to see if it percolates and I'm not sure how to go about this.
I have the following code for creating the…

Probably
- 426
- 5
- 19
0
votes
1 answer
How to determine transitive relation with union-find
I have the following data sets
6 - 7 -->means 6 and 7 are related
5 - 4 -->means 5 and 4 are related
4 - 6 -->means 4 and 6 are related
now how do i determine if 5 is related to 7 using union-find? Someone please guide me.

aries
- 849
- 3
- 11
- 24
0
votes
1 answer
Run time error in graph
I am implementing Graph for the first time and for that I took this problem from SPOJ.
Took help of geeksforgeeks, applied union find algorithm to find out whether or not graph contains a cycle but I get run time error (SIGSEGV).
Can you please help…

unixia
- 4,102
- 1
- 19
- 23
0
votes
1 answer
Having trouble with weighted and unweighted quick union finds
TLDR at bottom
I've been assigned a programming project at school to build a percolation model and i've come across an issue which has given me quite some confusion. First off, we were supposed to build an api to run a percolation simulation
public…

Michael Kimin Choo
- 165
- 1
- 4
- 10
0
votes
1 answer
Can we find the path between 2 node if they are connected using union-find algo?
I studied the union find algo and found it is very useful in following ways.
to find out if 2 node are connected or not
to compress the path. (save space)
if the problem is to find if 2 node connected or not , then we can use…

Suri
- 3,287
- 9
- 45
- 75