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
Eclipse Java WeightedQuickUnionUF
Currently working in Eclipse on a problem.
Data stucture weightedQuickUnionFind
What I have:
-a list of data in a separate .txt file which contains ID's of users. example:
0 5
0 2
1 3
1 2
2 5
3 7
What this is basically…

KimCheeFatChoyProgrammer
- 173
- 1
- 3
- 16
0
votes
1 answer
Initializing an Array C++
My code is trying to implement the union-find algorithm and I have the id[] array and the sz[] array. I initialize them in the Union-Find constructor, but once I try to use those arrays in the methods within the Union-Find class, it changes all the…

amahf
- 1
0
votes
1 answer
Union of disjoint sets
I am looking at disjoint sets that support the function of the Union.
The technique of height reduction of a tree:
We always merge the smaller tree to the greater one, i.e. we make the root of the smaller tree to point to the root of the greater…

Mary Star
- 375
- 7
- 27
0
votes
0 answers
How to you turn on a site and connect two sites when there are multiple dimensions?
Normally when I use union find, I create a one-dimensional array and initialize the value at each index with its position in the array. So for a 5 element array each element will have the same value as their index (0-4).
If I use union find data…

template boy
- 10,230
- 8
- 61
- 97
0
votes
1 answer
In a Union-Find algorithm, whether/how to adjust the rank of a node in path compression
Path compression involves assigning the root as the new parent of every node on the path - this may reduce the rank of the root, and possibly the rank of all nodes on the path. Is there a way to deal with this? And is it necessary to deal with this?…

Tesseract_R
- 29
- 1
0
votes
1 answer
Disjoint Set Operation Find_Set(x) using linked list
Its about naive Union-Find algorithm using linked-list representation of disjoint sets:
Find_Set(x) operation returns a pointer to the representative of the set containing element x.which requires O(1) time, since node containing x has a pointer…

Tanmoy Banerjee
- 1,433
- 3
- 22
- 31
0
votes
1 answer
Union Find to solve Traveling Salesman
I have to use the union find algorithm to solve the traveling salesman problem. I prettymuch got it done except for one problem I've just discovered. As it processes each edge, it will check for a cycle, which is done with the whole parent array…

Teddy Black
- 193
- 2
- 14
0
votes
0 answers
how could I make sure the index is the smallest in union-find algorithm?
I have a N*N boolean symmetric matrix to show the relationship of each element.
for example matrix
1 0 1
0 1 1
1 1 1
means element 1 has relationship with 1, 3; element 2 has relationship with 2,3, etc.
Now I want to cluster the elements, as the…

Freya Ren
- 2,086
- 6
- 29
- 39
0
votes
2 answers
Count how many different vectors left after union
I'm only using std::vector in this problem and each vector is ordered without duplicate. Now I want to union the vectors that have same numbers. So 2 3 can be union with 3 4 5 but not with 4 5 nor 1 5.
Example:
If I have following vectors...
1
1
2…

Arch1tect
- 4,128
- 10
- 48
- 69
-1
votes
2 answers
Leetcode Number of Province not passing edge case last few edge case
I try using the Union find method for this question but not passing this case, could somebody may be give me an insight to why that is?
find() : for find method there is path compression
union() : for union there is union by rank
Question link
So…

Intern
- 39
- 1
- 5
-1
votes
2 answers
Memory limit exceded error to find maximum value from each componenet in graph
Here is the question:
exmaple:
5
12 34 10 7 8
3
1 2
2 3
3 1
Output:
56
Groups are formed as: [1,2,3][4][5].
Maximum collection is 56 (collected by volunteer 1, 2, and 3).
My logic was to run a dfs and store the maximum value among all…

Chaitanya Gujarathi
- 137
- 3
- 9
-1
votes
1 answer
Union Find Algorithm - reading other's code
I was trying to understand the code on https://www.geeksforgeeks.org/union-find/.
I am not sure whether "parent" in the highlighted part refers to a "defaultdict" object that the user needs to input. Further, could someone explain to me where the…

henryl
- 9
-1
votes
1 answer
How to implement Union-Find using linked lists?
I need to write a piece of code using the Kruskal algorithm, which in turn needs the Union-Find algorithm.
This includes the methods Make-Set(x), Find-Set(x) and Union(x, y).
I need to implement them using linked lists, but I am not sure of how to…

CoderCat
- 101
- 1
- 2
- 9
-2
votes
1 answer
Java algorithm problem: output one of the two connected paths
/**
* The Problem:
*
* We have a list of tasks. Each task can depend on other tasks.
* For example if task A depends on task B then B should run before A.
*
* Implement the "getTaskWithDependencies" method such that it returns a list of task names…

Joy Cheng
- 23
- 6
-2
votes
1 answer
Union-Find Algorithm (Finding Cycle) Without Using Malloc
I've been advised that using malloc in a c++ program shouldn't be done. How can I convert this to a non-malloc code? Thank you!
https://www.geeksforgeeks.org/union-find-algorithm-set-2-union-by-rank/

Bel
- 45
- 7