Questions tagged [union-find]

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

184 questions
0
votes
2 answers

Why is my Union Find Disjoint Sets algo for this problem not passing all test cases?

Sample input: 1 3 2 1 2 2 3 First line = # of test cases First number of second line = number of people Second number of second line = number of friendships, F Following F lines = the friendships Output would be the size of the largest friend…
J. Doe
  • 85
  • 1
  • 6
0
votes
1 answer

Partitioning bounding boxes with Union-Find

I want to partition an array of bounding boxes (with coordinates [ymin, xmin, ymax, xmax]) as it is described in this paper [https://arxiv.org/pdf/1710.06677.pdf][1]. My threshold will be intersection over union for grouping two bounding boxes…
kneazle
  • 335
  • 4
  • 14
0
votes
1 answer

Persistent Union-Find with occasional removals

I have a set of half a million items stored in the database and need the following operations: union(x, y) just like in Union-Find findAll(x) finding all y such that find(x) == find(y) ununion(x, y) reverting a former union operation This is a…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
0
votes
0 answers

Find a path from top-btm with Union Find

PROBLEMS Is there a path from the top to bottom of a field? Is there still a path if a circular sensor area is added? How many sensors can be added while still having a path? What I tried Created a 2D array Used UnionFind Algorithm to find if…
0
votes
1 answer

Union-Find leetcode question exceeding time limit

I am solving this problem on leetcode https://leetcode.com/problems/sentence-similarity-ii/description/ that involves implementing the union-find algorithm to find out if two sentences are similar or not given a list of pairs representing similar…
Kareem Aboughazala
  • 535
  • 1
  • 6
  • 15
0
votes
0 answers

Why do I keep getting TLE for POJ 1984 -- Navigation Nightmare?

#include #include #include #include using namespace std; struct vectors{ int x; int y; bool visited; vectors(int x = 0, int y = 0){ this -> x = x; this -> y = y; visited…
0
votes
1 answer

Time complexity of a union-find solution

What is the approximately time complexity of the solution to the below problem? If we assume that due to path compression, each call to self.find() is roughly amortized to ~O(1) Problem Statement: Given a list accounts, each element accounts[i] is…
user1008636
  • 2,989
  • 11
  • 31
  • 45
0
votes
2 answers

How to generate the worst case for disjoint set with only path compression?

A disjoint set with only path compression implemented is like this: // In cpp. int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); } int Union(int a, int b) { f[Find(a)] = Find(b); } From wiki I've learned about it has a worst complexity of…
karatoga
  • 513
  • 4
  • 14
0
votes
1 answer

Union Find Data Structure Exercise

I just encountered an exercise which I either don't get or has an error in the exersice: The following table coantains a Union-Find data structre to the set of sets {{1,2,3,9},{4,6,7},{5,8},{10}}. Complement the table s.t. it contains the Union-Find…
xotix
  • 494
  • 1
  • 13
  • 41
0
votes
1 answer

Union-Find implementation does not update parent tags

I'm trying to create some sets of Strings and then merge some of these sets so that they have the same tag (of type usize). Once I initialize the map, I start adding strings: self.clusters.make_set("a"); self.clusters.make_set("b"); When I call…
Alessandro
  • 4,000
  • 12
  • 63
  • 131
0
votes
1 answer

Union-Find path compression efficiency

I found some online union-find tutorial depicted path compression technique to get even less than O(log(N)) complexity for find(), below was the path compression implementation in this blog, int root (int Arr[], int i) { while(Arr[i] != i) { …
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0
votes
1 answer

Swap LexOrder Union Find

So I'm doing interview practice questions and I came across this one: Given a string str and array of pairs that indicates which indices in the string can be swapped, return the lexicographically largest string that results from doing the allowed…
Stephen Agwu
  • 1,013
  • 2
  • 15
  • 29
0
votes
0 answers

Restore Kruskal's MST

The question goes as follows: After doing Kruskal for finding minimum spanning tree using the Union-find, We are given an array of disjoint sets of 10 vertices. Can you restore the MST's that Kruskal's found only using the given array: Note: If the…
0
votes
2 answers

Confusion regarding the quick union algorithm when applied to the sequence of pairs: 1-2,2-3,3-4

As far as my understanding goes in the quick-union algorithm when a pair is to be processed we first do the FIND operation and check if the roots of the trees in which these objects are present are equal or not. In the case they are not equal we…
iosdev
  • 53
  • 8
0
votes
0 answers

QuickUnion.cpp:101:1:expected ‘}’ at end of input } Error

I'm getting this error while executing a simple program for implementing the Quick Union Algorithm. I couldn't find anything wrong with the curly braces. I have posted the code below. Kindly review it. #include #include #ifdef…