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
4
votes
2 answers

O(1) Make, Find, Union in Disjoint Sets Data Structure

Today, I had discussion with someone about Kruskal Minimum Spanning Tree algorithm because of page 13 of this slide. The author of the presentation said that if we implement disjoint sets using (doubly) linked list, the performance for Make and…
monn
  • 717
  • 1
  • 5
  • 13
4
votes
1 answer

What is the order in this Union by Rank diagram?

I'm having trouble understanding the following diagram: Why is A linked to D instead of B? Why is C linked to F instead of D?
Sam
  • 934
  • 2
  • 11
  • 21
3
votes
3 answers

Do the order of edges matter in union find?

I am learning union-find and to understand it better, I have written a small program: #include #include #include using namespace std; vector parent, sz; int find(int i) { if(parent[i]==i) return i; …
Someone
  • 611
  • 4
  • 13
3
votes
1 answer

Give minimum permutation weight for edges such that a given set of edge is the Minimum Spanning Tree

Question: Given a graph of N nodes and M edges, the edges are indexed from 1 -> M. It is guaranteed that there's a path between any 2 nodes. You need to assign weights for M edges. The weights are in the range of [1...M], and each number can only…
unglinh279
  • 675
  • 4
  • 24
3
votes
2 answers

How to implement a union-find (disjoint set) data structure in Coq?

I am quite new to Coq, but for my project I have to use a union-find data structure in Coq. Are there any implementations of the union-find (disjoint set) data structure in Coq? If not, can someone provide an implementation or some ideas? It doesn't…
Alex
  • 2,915
  • 5
  • 28
  • 38
3
votes
1 answer

My C++ function gives unusual error, regarding declaration

#include using namespace std; void union(int x, int y, int link[], int size[]) { int a = find(x, link); int b = find(y, link); if (size[a] < size[b]) swap(a,b); if ( a != b) { size[a] += size[b]; …
Anant
  • 302
  • 2
  • 11
3
votes
2 answers

Iterating over classes in a disjoint set data structure

I've implemented a disjoint set data structure for my program and I realized I need to iterate over all equivalence classes. Searching the web, I didn't find any useful information on the best way to implement that or how it influences complexity.…
3
votes
1 answer

Algorithm: use union find to count number of islands

Suppose you need to count the number of islands on a matrix {1, 1, 0, 0, 0}, {0, 1, 0, 0, 1}, {1, 0, 0, 1, 1}, {0, 0, 0, 0, 0}, {1, 0, 1, 0, 1} We…
newBike
  • 14,385
  • 29
  • 109
  • 192
3
votes
1 answer

Find number of pairs of disjoint sets in a list of sets

The problem statement is as follows: given a list of n sets, each containing k integers, find the number of pairs of disjoint sets. Suppose the possible elements of the sets are positive and bounded above by c > n, and suppose k << n. I'm trying to…
py1123
  • 31
  • 1
3
votes
0 answers

Is there a DB system which supports Union-Find (Disjoint Sets) data structure

Basically looking for a DB which supports this data structure OOTB
user976850
  • 1,086
  • 3
  • 13
  • 25
3
votes
4 answers

Check if two dictionaries are disjoint

Is there an easier/faster way to find out if two dictionaries are disjoint than calculating their intersection? For the intersection I found this answer, so the disjoint-test would look like this: def dicts_disjoint(a, b): keys_a =…
Johannes
  • 3,300
  • 2
  • 20
  • 35
3
votes
1 answer

Disjoint Set implementation in C++

I came across this problem in an Online contest and I'm trying to solve it using Disjoint Set Data-structure. Problem Definition: Bob visits a nuclear power plant during his school excursion. He observes that there are n nuclear rods in the plant…
Raghav
  • 169
  • 1
  • 10
3
votes
0 answers

Make 3 disjoint connect graphs with special types of edges

There are N vertices and M edges in the world. There are three types of edges: type "AB", "BC", and "CA". There are three people A, B, and C. Each person can use an edge if and only if its type name contains the person's name. (For example, A can…
K.R.
  • 31
  • 3
3
votes
2 answers

Detect cycle in a graph using Kruskal's algorithm

I'm implementing Kruskal's algorithm, which is a well-known approach to finding the minimum spanning tree of a weighted graph. However, I am adapting it to find cycles in a graph. This is the pseudocode for Kruskal's algorithm: KRUSKAL(G): 1 A = ∅ 2…
Abhinav Gauniyal
  • 7,034
  • 7
  • 50
  • 93
3
votes
1 answer

set of vertex-disjoint cycles so that each vertex belongs to a cycle

Here I have a directed graph G. I need to to determine whether there exists a set of vertex-disjoint cycles so that each vertex belongs to a cycle. I'm not sure if this can be done in polynomial time or if its NP-Complete? Can anyone atleast point…
jtaylor
  • 45
  • 6
1 2
3
12 13