Questions tagged [disjoint-union]

55 questions
0
votes
0 answers

Multithreaded union-find algorithm not working properly

I am trying to implement a multithreaded Union-Find algorithm as outlined in this paper (https://citeseerx.ist.psu.edu/viewdoc/download?oi=10.1.1.56.8354&rep=rep1&type=pdf). Using this, I am trying to find out the number of connected components in…
0
votes
0 answers

Representatives in Disjoint Set Union

The goal is to efficiently obtain representatives of every set. Obtaining the root as representative is better since it gives more information about the set; nodes are often augmented with properties of their subtrees. For example, given the…
AustinBest
  • 23
  • 5
0
votes
0 answers

Getting ambiguous error for Vector. How to Fix it?

#include using namespace std; const int N = 1e5 + 10; vector parent(N); vector rank(N); // size void make(int v) { parent[v] = v; rank[v] = 1;//"rank" is ambiguous } int find(int v) { if (v == parent[v]) …
0
votes
1 answer

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 surrounded by water and is formed by connecting…
Someone
  • 611
  • 4
  • 13
0
votes
0 answers

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 the amortized complexity of the union operation is…
0
votes
1 answer

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.parent.parent x := x.parent return x My first…
0
votes
1 answer

Can this problem done without bfs or storing edges?

You are given an undirected connected graph with n nodes and n edges. Now Given two nodes a and b. find the number of edges that lies in path from a to b but are not part of cycle. (as number of edges is n there will be a cycle for sure). Can this…
0
votes
2 answers

In Disjoint Set Union (D.S.U.), why do we make the smaller sized subset as the child of the larger sized subset while performing the union operation?

I recently came across D.S.U. and its applications on the tree.As i was solving the related problems, I got Time Limit Exceeded error in some so i read the tutorial again and there I found that an improvised version of the normal union is…
0
votes
1 answer

Disjoint set union implementation using c++

I am implementing Disjoint-Set Union by Rank and Path Compression in c++ according to the cp algorithm.But here I am getting an error reference to 'rank' is ambiguous . I have read many articles about this error but could not get any satisfactory…
user9857651
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

fastest way to merge duplicate cells in without looping Excel

I have cells containing duplicate values that i want to merge quickly. The table looks like this: Sub MergeCells() Application.DisplayAlerts = False Dim n As Name Dim fc As FormatCondition Dim Rng As Range, R As Range Dim lRow As Long Dim I&,…
sifar
  • 1,086
  • 1
  • 17
  • 43
0
votes
1 answer

How should Union operation in disjoint-set data structure properly implemented?

There are many different descriptions and examples for the disjoint-set structure available on-line. In some cases, for each set, it stores "rank". When a set is merged into another set, the rank of the former is increased by 1, if they are of the…
user31264
  • 6,557
  • 3
  • 26
  • 40
0
votes
1 answer

Graph Traversal count clouds [python]

Given a 2D grid skyMap composed of '1's (clouds) and '0's (clear sky), count the number of clouds. A cloud is surrounded by clear sky, and is formed by connecting adjacent clouds horizontally or vertically. You can assume that all four edges of the…
aerin
  • 20,607
  • 28
  • 102
  • 140
0
votes
3 answers

Code to form a set from a list of element pairs in java

Say I have a list of pair of elements like (1, 2) (3, 4) where no duplicates are present and for a pair (p, q) p != q. How to form a set from this elements using simple code (I do not intend to use a data structure like disjoint set and unions but…
0
votes
1 answer

How to detect a cycle in an Undirected Graph using Disjoint Sets?

Algorithm: For each edge (u, v) in the Adjacency list: If u and v do not belong to the same set: Union(u, v) else: return true // cycle detected return false Graph: (1)-------(2) Adjacency List: [1] -> [2] [2] -> [1] Disjoint-Sets: {{1},…
Abhishek
  • 432
  • 5
  • 19