Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
127 views

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 ...
Erg's user avatar
  • 79
1 vote
2 answers
240 views

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'...
Nitaa a's user avatar
  • 143
1 vote
0 answers
51 views

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 ...
PacificNW_Lover's user avatar
0 votes
1 answer
44 views

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 ...
Lisa's user avatar
  • 4,430
0 votes
0 answers
45 views

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 ...
Tapananshu Gandhi's user avatar
0 votes
1 answer
169 views

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. ...
TripleCamera's user avatar
0 votes
1 answer
62 views

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 ...
blockerinho's user avatar
-1 votes
1 answer
112 views

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 ...
aha's user avatar
  • 1
0 votes
1 answer
295 views

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 ...
flameshooter09's user avatar
2 votes
1 answer
288 views

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 ...
David's user avatar
  • 632
0 votes
1 answer
173 views

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%...
PKuhn's user avatar
  • 1,360
2 votes
1 answer
312 views

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 ...
user129393192's user avatar
0 votes
1 answer
132 views

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 ...
Vahid S. Bokharaie's user avatar
1 vote
1 answer
213 views

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 ...
Yufei Zheng's user avatar
0 votes
1 answer
35 views

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 ...
Ali Alsawad's user avatar
0 votes
0 answers
140 views

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 ...
Xiao's user avatar
  • 31
2 votes
0 answers
430 views

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 = [{...
joseville's user avatar
  • 1,023
3 votes
1 answer
664 views

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 ...
Vimit Dhawan's user avatar
0 votes
0 answers
203 views

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 ...
Paul's user avatar
  • 353
0 votes
1 answer
126 views

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 ...
Dan's user avatar
  • 185
0 votes
2 answers
879 views

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, ...
bells's user avatar
  • 11
0 votes
1 answer
221 views

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 ...
Stack Realtek's user avatar
0 votes
1 answer
151 views

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&...
Vertero's user avatar
6 votes
1 answer
5k views

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 ...
Someone's user avatar
  • 643
2 votes
2 answers
190 views

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, ...
Pawan Nirpal's user avatar
4 votes
1 answer
892 views

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 ...
Bart Louwers's user avatar
0 votes
0 answers
886 views

#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;//"...
Anish Kumar Mohanty's user avatar
3 votes
3 answers
318 views

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>...
Someone's user avatar
  • 643
1 vote
1 answer
544 views

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 ...
Someone's user avatar
  • 643
1 vote
0 answers
183 views

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 ...
Xiao's user avatar
  • 31
3 votes
1 answer
273 views

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 ...
unglinh279's user avatar
0 votes
0 answers
348 views

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 ...
chae yeon's user avatar
0 votes
1 answer
120 views

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[...
chae yeon's user avatar
0 votes
2 answers
562 views

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 ...
Someone's user avatar
  • 643
1 vote
1 answer
65 views

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 ...
Mysteryxx3's user avatar
-1 votes
2 answers
79 views

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 ...
Intern's user avatar
  • 39
0 votes
0 answers
195 views

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 ...
Göktuğ ÖCAL's user avatar
-3 votes
1 answer
1k views

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. ...
WilliamHarvey's user avatar
0 votes
0 answers
13 views

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 ...
Ramkrishna Sharma's user avatar
1 vote
1 answer
89 views

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 ...
A321's user avatar
  • 17
7 votes
1 answer
887 views

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: //...
Rishabh Kumar Singh's user avatar
3 votes
2 answers
777 views

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 ...
Alex's user avatar
  • 3,016
1 vote
3 answers
453 views

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 ...
Leon's user avatar
  • 362
0 votes
0 answers
498 views

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 ...
Ali's user avatar
  • 13
0 votes
1 answer
5k views

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 ...
Henry's user avatar
  • 3,250
1 vote
1 answer
141 views

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 ...
Suniti Jain's user avatar
1 vote
2 answers
783 views

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 ...
Mistakamikaze's user avatar
1 vote
1 answer
374 views

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 ...
Marcello Faria's user avatar
0 votes
1 answer
737 views

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....
hack3r-0m's user avatar
  • 750
0 votes
0 answers
117 views

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 ...
Emanuele Illiano's user avatar

1
2 3 4 5