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
Self-referential struct in c++ for union-find
The following is a Java implementation of union-find, and I wish to replicate the same in C++:
class v_rank{
int position, rank;
v_rank parent;
public v_rank(int position){
this.position = position;
rank = 0;
…

Karmah24
- 485
- 1
- 5
- 14
0
votes
1 answer
Union Find in Java
I am trying to implement the union-find algorithm. Basically the part of the algorithm that I am struggling with is the union part. What is supposed to happen is that there is a list of numbers (starts off with all of them being their index in the…

Ben Naylor
- 29
- 6
0
votes
1 answer
Union-find algorithm does not return expected result
I implemented the following union-find algorithm using this example:
import numpy as np
class UnionFind(object):
def __init__(self, edges):
self.edges = edges
self.n_edges = np.max(edges) + 1
self.data =…

Gilfoyle
- 3,282
- 3
- 47
- 83
0
votes
1 answer
finding if there is a way from the top to a specific element in 2-dimensional array
I have a 2-dimensional array, I want to check if there is any way from the top row to a specific element in the array.
The way means: that there is continuously connected 1 from top to the element.
I've implemented a function to solve it: I can…

Ahmad Ali
- 704
- 1
- 10
- 28
0
votes
1 answer
proof of time complexity of union find with path compression
The Wikipedia page: wikipedia page states that
If m operations, either Union or Find, are applied to n elements, the total run time is O(m log*n).
The detailed analysis arrived at this result is :
My questions are:
Shouldn't the sum be…
0
votes
1 answer
Find the number of connected components in undirected graph using Union Find
I've been staring at this algorithm for a while but couldn't spot what I've missed.
Logic:
Init all isolated components
union frm, to component in each edge and decrement # components if those components aren't already connected.
Question: how…

jen007
- 1,389
- 3
- 15
- 19
0
votes
0 answers
Use union-find data structure to find connected component in a graph through Python
I'm working on building a graph for word ladder problem using Python. I try to use union-find data structure to find connected component in the graph, but since I'm new to programming, I feel very confused how to implement it in Python even I have…

FantasticAI
- 99
- 4
0
votes
2 answers
How do I use union find data structure to group Strings?
I have been using Union-Find (Disjoint set) for a lot of graph problems and know how this works. But I have almost always used this data structure with integers or numbers. While solving this leetcode problem I need to group strings and I am…

Ezio
- 2,837
- 2
- 29
- 45
0
votes
1 answer
Disjoint-Set (union-find) data structure in MATLAB
Are there any implementations of the union-find algorithm in MATLAB?
If not, is it possible to implement it using a classdef or any other method?
I looked online a lot and couldn't find any implementations for MATLAB! This was the last place I could…

saad.sawash
- 229
- 1
- 10
0
votes
1 answer
How to select elements in a Quick union operation?
There are a set of elements S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Here there are 10 elements (N = 10). An array arr to manage the connectivity of the elements. Arr[ ] that is indexed by elements of sets, which are of size N (as N elements in set),…

Kshitij Zutshi
- 69
- 7
0
votes
1 answer
Implementing Union-Find, getting TypeError: 'builtin_function_or_method' object is not subscriptable
I am trying to implement a quick-union with path compression algorithm and for some reason I'm getting a TypeError: 'builtin_function_or_method' object is not subscriptable when testing. It all looks good to me. Here's the code; I appreciate your…

qotsa42
- 147
- 1
- 1
- 11
0
votes
2 answers
Why is the time complexity O(lgN) for an operation in weighted union find algorithm?
So everywhere I see weighted union find algorithm, they use this approach:
Maintain an array pointing to the parent node of a particular node
Maintain an array denoting the size of the tree a node is in
For union (p,q) merge the smaller tree with…

Little_idiot
- 125
- 1
- 8
0
votes
1 answer
How can I implement the Union-Find algorithm?
I'm trying to implement the Union-Find algorithm, but all of the implementations i've looked up use integers. I need to implement the algorithm so that I can call the union() and the connected() methods in this way: union(Vertex v, Vertex, w) -…

Nicolás Cárdenas
- 53
- 5
0
votes
1 answer
How to implement the operation FindMin(x) on a union-find data structure?
S represents the set of integers from 1 to n. Consider the union-find data structure where - besides the operations union(A, B) and find(x) - you are interested in returning the minimum element of the set to which x belongs.
Suggest a data structure…

pippi2424
- 21
- 5
0
votes
1 answer
How to correctly implement wighted union and path compression in a UnionFind data structure
I am trying to implement a Union-Find/Disjoint-Set data structure in C, using weighted Union and path compression in Find. I have some questions as to how the weighted union should be implemented to reduce time complexity when compared to the non…

Desperados
- 434
- 5
- 13