203 questions
1
vote
1
answer
127
views
Most efficient identification and concise expression of a set of disjoint elements
I am attempting to determine how to most efficiently identify the sets consisting of the least number of terms for a group of disjoint sets.
I have a set of Boxes (B##) and Cartons (S##) which are ...
1
vote
2
answers
240
views
Tracking the number of connected components when adding and removing edges
I'm working with an undirected graph where I need to frequently add and remove edges. I also need to efficiently determine the number of connected components after each operation.
For adding edges, I'...
1
vote
0
answers
51
views
DSU with Union Find for graph puzzle - JUnit test failing when trying to cover overlapping index in grid
I am using Disjoint Set Union (DSU) and Union Find to solve a graph problem.
The entry point function takes an input string with coordinates defined by (line number, char number), starting at the top ...
0
votes
1
answer
44
views
Can I represent concepts like disjoint directly using GeoSPARQL?
Can I represent that a georegion is disjoint (the exact inverse) from another using GeoSPARQL?
I want to represent (in RDF using my own ontology along with GeoSPARQL) that I have an entity inside some ...
0
votes
0
answers
45
views
Logical Error in my implementation for the problem "Draughts" of Codechef
I have written this code for the problem "Draughts" of codechef but only few testcases are getting passed. Can anyone tell what is the error in my logic?
Furik and Rubik have come to the ...
0
votes
1
answer
169
views
How to perform split operation on a disjoint set?
I am working on an undirected graph which supports:
addPerson: Inserting a node person.
addRelation: Adding an edge between id1 and id2.
modifyRelation: Modify/Remove an edge between id1 and id2.
...
0
votes
1
answer
62
views
Complexity in Union of disjointed sets with lists
I can't understand why the complexity of a weighted-union of disjointed sets with lists has complexity O(log n) for one Union and O(nlogn) for n unions.
I know that the complexity is based uppon the ...
-1
votes
1
answer
112
views
How to draw a visualization of disjoined set structure for the following p[] array?
I have answered the following assignment:
Problem 1. Draw a visualization of the disjoint-set structure as we did in class for the following p[] array.
i = [0 1 2 3 4 5 6 7 8 9],
p[i]= [2 2 2 3 4 4 ...
0
votes
1
answer
295
views
Can I change the solution to the DSU painting subarrays question?
The link to the post about this algorithm which I have a question for is here: https://cp-algorithms.com/data_structures/disjoint_set_union.html
My question is specifically about this section
We have ...
2
votes
1
answer
288
views
Consequences of disjoint set union path compression in union by size
When doing union by size, you compare the size of the nodes that you're trying to unify.
I found this code on codeforces that shows how to build a DSU with path compression and union by size:
#include ...
0
votes
1
answer
173
views
Union-Find: Do you do find operations in the union when using path compression
My question is closely related to: https://stackoverflow.com/questions/49574421/path-compression-is-enough-for-disjoint-set-forests-why-do-we-need-union-by-ra#:~:text=We%20use%20both%20the%20union,the%...
2
votes
1
answer
312
views
Finding the minimum cost for 'm' compatible elements for group 1 and group 2 (algorithm)
Here is a problem statement. I recently had an interview question regarding this:
given arrays compatible1, compatible2, and cost of length n >= 1. cost[i] represents the cost of element i. the ...
0
votes
1
answer
132
views
Find all disjoint subsets of a binray matrix in Pyhton
I have a binary matrix, and I want to find all disjoint subsets that exist in this matrix. To clarify the problem, the matrix is a collection of image masks, masks of irregular shapes, and each ...
1
vote
1
answer
213
views
minimum collection of vertice disjoint path that covers a given vertice set
Problem
Given:
A directed graph G
A source vertex s in G and a target vertex t in G
A set S of vertices of G
I want to find a collection of paths from s to t that covers S.
Then I want to partition ...
0
votes
1
answer
35
views
Merging database tables using rank and path compression heuristics
I am having trouble with the following problem in my data structures course. The errors provided by the course are rather ambiguous and I am not able to discern where the bug lies.
NOTE: The error ...
0
votes
0
answers
140
views
Disjoint Union of Strings
I have a vector of vector of strings of size == 2 with the following format
vector<vector<string>> equations;
where equations[i]={"Hi", "I am"};
I want to make a ...
2
votes
0
answers
430
views
How to merge sets in better then O(len(set))?
I have a list of sets called groups. groups[i] is a set of labels (integers) that are part of the same group as i. For example,
# idx: 0 1 2 3 4 5 6 7
groups = [{...
3
votes
1
answer
664
views
Do we need to update the ranks while path compression in Disjoint set data structure?
I was studying disjoint set data structure. I understand how rank helps us make shallow trees and path compression decrease tree height.
I can find the below code in most articles or study materials ...
0
votes
0
answers
203
views
The Value of Friendship : Disjoint set union
I am doing this challenge on HackerRank and I tried to use a mapping between students and sets to represent which group of friends the students belonged to :
The list of friends is instantiated with ...
0
votes
1
answer
126
views
Algorithm for Randomly selecting k elements from n with Some Elements Belonging to Disjoint Pairs
I need to randomly select k elements from a list of n. Let's say that:
n = (1,2,3,4,5,6,7,8,9,10)
and I want to randomly chose k = 4 elements and arrange them in random order. I am using Perl, so I ...
0
votes
2
answers
879
views
How to check which of multiple given sets are disjoint?
I want to write a method that uses the standard for loop to iterate through a given set of sets, and returns a hashmap that the disjoint sets are added to. I'm aware that the does not work correctly, ...
0
votes
1
answer
221
views
Disjoint set data structure in c
I want to implement the structure on the image in C language.
But I have a problem because the 2 structures created call each other and therefore pose a problem how can I remedy it?
set data structure ...
0
votes
1
answer
151
views
Minimal count of the disjoint set partitioning
I am looking for an efficient algorithm (if there is one) to solve the following problem:
Given a set S, whose elements are sets with only two elements. For simplicity, let' s say "two elements&...
6
votes
1
answer
5k
views
Is this Union Find really O(n) as they claim?
I am solving a problem on LeetCode:
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. So ...
2
votes
2
answers
190
views
Creating a data structure of integers and finding which component a given integer lies in
I have a set of 32 bit integers with which I will be making a data structure that will put these integers in different components ( like dsu ) the join operation has to be performed using bitwise and, ...
4
votes
1
answer
892
views
Optimize Union Find (Disjoint Set Union) implementation
I have implemented a Disjoint Set Union in C++ for a Kattis problem. However, my solution is inefficient, as I get TLA (Time Limit Exceeded) for the first hidden test case. Can anyone spot an ...
0
votes
0
answers
886
views
Getting ambiguous error for Vector. How to Fix it? [duplicate]
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> parent(N);
vector<int> rank(N); // size
void make(int v)
{
parent[v] = v;
rank[v] = 1;//"...
3
votes
3
answers
318
views
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 <iostream>
#include <vector>
#include <numeric>
using namespace std;
vector<int>...
1
vote
1
answer
544
views
Returning the right number of islands using Union Find
I am solving a question on LeetCode.com called Number of Islands:
Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is ...
1
vote
0
answers
183
views
Disjoint Set Union
I was solving a problem of Hackerrank in Graphs a particular question https://www.hackerrank.com/challenges/journey-to-the-moon/problem
I applied DSU but the answer is wrong even though the code is ...
3
votes
1
answer
273
views
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 ...
0
votes
0
answers
348
views
making kruskal's algorithm in c (segmentation fault)
In this code I want to make Kruskal's algorithm, which calculates a minimum
spanning tree of a given graph. And I want to use min-heap and disjoint set at the code.
To make time complexity of O(e log ...
0
votes
1
answer
120
views
Time complexity and height of disjoint sets using array in C
I found a quiz about the time complexity of disjointed sets when using an array.
Suppose we have nodes that are numbered from 0 to n-1. All we need is an array named parent, where the value of parent[...
0
votes
2
answers
562
views
How does this backtracking code ensure that the two strings don't have common elements?
I am trying this question on LeetCode:
Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they ...
1
vote
1
answer
65
views
Trouble with 'With' statements SQL query
I'm having difficulties writing an SQL query that has multiple WITH statements. I'm quite new to SQL so please bear with me. The context is unimportant but in this case, I'm trying to query a movie ...
-1
votes
2
answers
79
views
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 ...
0
votes
0
answers
195
views
Amortized complexity of the union operation
There are lots of sources about amortized complexity or union-find, quick-find operations but I couldn't find anything about the proof of single union operation complexity.
So, how can I prove that ...
-3
votes
1
answer
1k
views
How to solve this Union-Find disjoint set problem?
I am stuck on this problem:
https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1099
Currently, I have sets, where each element in the set are friends. ...
0
votes
0
answers
13
views
How does the Root Method Work in Quick-Union? [duplicate]
I've recently been studying the Princeton Algorithms course on Coursera. The course begins by teaching an algorithm called Quick-Union to solve the Dynamic Connectivity Problem..
While I understand ...
1
vote
1
answer
89
views
Node Set with disjoint Subset in CPLEX
I am currently trying to implement a directed weighted graph algorithm in CPLEX.
For that I need to initialize the following node set P which includes three different disjoint subsets.
Node Set P
...
7
votes
1
answer
887
views
Why don't we update rank for disjoint set after path compression?
I have made a template for disjoint set with rank heuristic and path compression.
template <typename T>
class disJSet
{
map<T,T> parent;
map<T,int> rank;
public:
//...
3
votes
2
answers
777
views
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 ...
1
vote
3
answers
453
views
LinkedHashMap vs LinkedHashSet for retrieving specific elements & retrieving in insertion order
I'm doing a problem that clearly requires usages of Set but I need to retrieve elements from a set in insertion order + retrieve specific elements.
But finding the specific element was too slow( I ...
0
votes
0
answers
498
views
How can I find and compute the K-shortest disjoint pair paths between two nodes in a graph?
I want to find and compute the K-shortest pair paths between two nodes in which each pair path contains two paths that they have not any shared links( only source and target nodes are common in each ...
0
votes
1
answer
5k
views
union by size vs union by rank in disjoint-set algorithm
The question in short: does union by rank work only in some circumstance?
For example, the input is:
(1, 2), (3,4), (3,5), after we run a disjoint-set algorithm on them:
one of the correct output ...
1
vote
1
answer
141
views
mother vertex using disjoint dataset in directed graph
I had the solution of classical Mother vertex problem using DSU (disjoint data set). I have used path compression.
i wanted to know if it is correct or not.I think time complexity O(E log(V)).
the ...
1
vote
2
answers
783
views
SQL Check if two columns from two tables are completely disjoint
I have two tables
CREATE TABLE A
ID INT PRIMARY KEY
....
CREATE TABLE B
ID INT PRIMARY KEY
....
How do I check if A.ID and B.ID are disjoint using postgres.
Disjoint meaning ...
1
vote
1
answer
374
views
union find set algorithm return parent[v] = find_set(parent[v]); means
int find_set(int v) {
if (v == parent[v])
return v;
return parent[v] = find_set(parent[v]); }
This is a slice of code of disjoin set algorithm
can i ask what is the meaning and purpose of return ...
0
votes
1
answer
737
views
Find() operation for disjoint sets using "Path Halving"
According to Disjoint-set_data_structure, In Union section, I have a problem understanding the implementation of Path Halving approach.
function Find(x)
while x.parent ≠ x
x.parent := x....
0
votes
0
answers
117
views
Makeset on node, what about the nodes the nodes linked to it?
I'm doing a project based on hashtables and disjoint sets, while implementing the makeset function for the nodes i had a doubt about it. This is the pseuodocode of the makeset function (i'm using path ...