Questions tagged [disjoint-sets]

Anything related to disjoint sets, i.e. mathematical sets that have no element in common.

Anything related to disjoint sets, i.e. mathematical sets that have no element in common.

194 questions
2
votes
3 answers

how to make sets and solve unions in disjoint set data structures?

i am getting a problem in calculating output of the following question which i got to solve in a quiz. the code is :- Consider the following program: for i from 1 to 12: MakeSet(i) Union(2, 10) Union(7, 5) Union(6, 1) Union(3, 4) Union(5,…
Ajay
  • 49
  • 2
  • 4
2
votes
1 answer

how to calculate height of disjoint trees implemented with union by rank heuristic?

Since very long i am trying to solve a question from a quiz , but i am getting wrong answer , the question is as follows :- Consider the program: for i from 1 to 12: MakeSet(i) Union(2, 10) Union(7, 5) Union(6, 1) Union(3, 4) Union(5, 11) Union(7,…
Ajay
  • 49
  • 2
  • 4
2
votes
4 answers

How to test all items of a list are disjoint?

Given a list of multiple iterables, I want to test if all items are disjoint. two sets are said to be disjoint if they have no element in common Example: iterables = ["AB", "CDE", "AF"] all_disjoint(iterables) # False iterables = ["AB", "CDE",…
pylang
  • 40,867
  • 14
  • 129
  • 121
2
votes
1 answer

How does Union-Find relate or differ to Graphs?

I understand that the former is a data structure while the latter is a mathematical structure. But when implemented, they seem to share many of the same features and behaviors. Each element in the disjoint-set can be considered a vertex in a graph.…
2
votes
1 answer

Divide a graph into same size disjoint sets with minimum cut

Is there any algorithm or code that divide graph nodes into two or more disjoint sets that satisfy following conditions: first, only edges allowed to remove. second, edges are weighted and those that would be removed must has minimum weight(minimum…
m b
  • 61
  • 6
2
votes
2 answers

Time Complexity of Array based Disjoint-Set data structure

I was solving this question on CodeChef and going through the editorial. Here's the pseudo-code for the implemented disjoint-set algorithm : Initialize parent[i] = i Let S[i] denote the initial array. int find(int i) int j …
Naveen
  • 7,944
  • 12
  • 78
  • 165
2
votes
1 answer

How to implement a maze using disjoint sets?

Here's the DisjointSet class i use : public class DisjointSet{ public DisjointSet(int size){ s = new int[size]; for(int i = 0; i < size; ++i){ s[i] = -1; } } public void union(int el1, int el2){ …
Zachariel
  • 96
  • 1
  • 13
2
votes
4 answers

Efficient algorithm to determine if two sets of numbers are disjoint

Practicing for software developer interviews and got stuck on an algorithm question. Given two sets of unsorted integers with array of length m and other of length n and where m < n find an efficient algorithm to determine if the sets are…
MNRC
  • 175
  • 2
  • 12
2
votes
1 answer

Graph Algorithm / Disjoint Set

I am trying to solve this problem but unable to do it fast. In short - we have a graph (directed) and we want to find out from which node (a set of nodes to select from is given) we can visit the most nodes. A straightforward implementation will be…
Varun Sharma
  • 2,591
  • 8
  • 45
  • 63
2
votes
3 answers

Three-way set Disjointness

this is a question from my practice problems for an upcoming test. I was hoping to get help in finding a more efficient solution to this problem. Right now, I know I can solve this type of problem just by using 3 simple for loops, but that would be…
Plazsma
  • 55
  • 2
  • 4
2
votes
3 answers

Implementing path compression in a disjoint set data structure?

Here is my Objective-C implementation of a disjoint set. - Positive number point to parent. - Negative number indicate root & children count. (So they each start disjointed at -1.) - The index acts as the data I am grouping. Seems to work ok... just…
Rakka Rage
  • 15,941
  • 8
  • 33
  • 45
2
votes
0 answers

Forming Disjoint-Sets of nodes of MST

I have been N nodes and N-1 edges,basically undirected acyclic MST. I want to basically count number of disjoint set of nodes. Two nodes belong to set if they have same parent and and degree of nodes are same. For eg. In the given tree . {3,4}…
gizmo17
  • 31
  • 8
2
votes
1 answer

Disjoint-sets for really big data

Are there any enhanced Disjoint-sets algorithm for really big data (such as more than 2^32 elements and more than 2^32 pair to union)? Obviously the biggest problem is that I cannot make such a large array, so I'm wondering if there is a better…
huangcd
  • 2,369
  • 3
  • 18
  • 26
2
votes
3 answers

Disjoint set as linked list

Can anyone point me to some info on Disjoint sets as linked list? I cant find any code on this. Language C++
Bramble
  • 1,395
  • 13
  • 39
  • 55
2
votes
2 answers

Can BFS find cycles in a graph?

I am new to graph theory, and so far I have learned only BFS and Disjoint sets in graph theory. If there is a cycle in a given, undirected, connected graph, can I find it using BFS ? My intention is to print all the vertices in the cycle. Thanks in…
odbhut.shei.chhele
  • 5,834
  • 16
  • 69
  • 109