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

various ways and their runtime to check if a path exists between two nodes or vertices?

I have seen articles in SO and elsewhere, where the following methods are cited for determining if a path exists between two nodes in a graph. I would like to know if any one is better than the other? Breadth First Search - O(V + E) Depth First…
3
votes
2 answers

Disjoint set using Searching and Sorting

I got a question in my algorithm class and i am unable to solve it. The question states that Theres is a Sorting Algorithm with O(nlogn) and searching is done by Binary search taking O(log n). Two sets are give P &Q and i have to design an algorithm…
3
votes
3 answers

Do I need to take explicit actions to facilitate sharing with persistent data structures?

I come from an imperative background and am trying to implement a simple disjoint sets (“union-find”) data structure to get some practice with creating and modifying (persistent) data structures in Haskell. The goal is to have a simple…
beta
  • 2,380
  • 21
  • 38
3
votes
1 answer

Disjoint set with Union by Size and Path Compression; possible for taller tree to become subtree of shorter tree?

Hi this is my first time posting here, I have been trying to work out a question for studying but haven't been able to figure it out: We consider the forest implementation of the disjoint-set abstract data type, with Weighted Union by size and Path…
FluffyBeing
  • 448
  • 1
  • 11
  • 27
3
votes
3 answers

When is it dangerous to have too many dynamic arrays?

I'm currently writing code for an assignment that deals with cities and bridges. I have to print the cities and bridges out in their respected districts such as: //unorganized inputs from user given the # of "paths" we need 4 // the # of…
Chris
  • 57
  • 1
  • 7
2
votes
3 answers

Amortized time per operation using disjoint sets

I happened to read on Wikipedia that the amortized time per operation on a disjoint set (union two elements, find parent of a specific element) is O(a(n)), where a(n) is the inverse Ackermann function, which grows very fast. Can anyone explain why…
ooboo
  • 16,259
  • 13
  • 37
  • 32
2
votes
1 answer

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 = [{0}, {1}, {2,5,6}, {3}, {4,7}, {2,5,6}, {2,5,6},…
joseville
  • 685
  • 3
  • 16
2
votes
2 answers

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, if the bitwise and is not zero of two integers…
2
votes
1 answer

Disjoint subgraphs in ArangoDB AQL

Given a graph database I have an actors vetices collection that has edges connecting it to a scenes vertices collection. I'm having trouble creating a query where I can select all the disjoint subgraphs, that is: given subgraphs A and B in the…
Rogério Peixoto
  • 2,176
  • 2
  • 23
  • 31
2
votes
1 answer

What is the complexity of path compression technique for disjoint set algorithm?

I was studying the disjoint algorithm with the union by rank and path compression. It is clear to me if Union by rank is used then the find() operation complexity is O(log(n)). But I wonder what is the complexity of the path compression technique…
2
votes
1 answer

How many ways are there to color uncolored edges in a circle

given n points on a circle and all edges (C(2,n)) are drawn. Some of these edges are already colored in blue or red. You should find out how many ways are possible to color rested edges in order to have final picture with conditions below: all…
Mahsirat
  • 79
  • 7
2
votes
1 answer

Boost Disjoint sets: How to retrieve sets?

I am trying to use disjoint sets from Boost but, after swimming all day through StackOverflow and the documentation I could not solve my problem. The main problem is: given some maps that will act as Rank and Parent, of an int element type (in the…
Adrian
  • 755
  • 9
  • 17
2
votes
2 answers

Kruskal's algorithm and disjoint-set data structure: Do I need the following two lines of code?

I've implemented Kruskal's algorithm in C++ using the disjoint-set data structure according to Wikipedia like this: #include #include #define MAX_EDGES 10000000 #define MAX_VERTICES 200001 using namespace std; int…
Alexandros
  • 3,044
  • 1
  • 23
  • 37
2
votes
1 answer

Why rank is not equal to height of the set in disjoint set?

I have recently read about a data structure disjoint-set-union. I am confused about the rank heuristic. I have read that "rank is not height of the tree set". I am unable to find this claim right. It is because when rank heuristic is used for union…
Anyway
  • 21
  • 3
2
votes
1 answer

Check if lists are disjoint

I need to check if two lists have any elements in common. I just need a yes/no - I don't need the actual list of common elements. I could use Enumerable.Intersect() but this does actually return the set of matching items which seems like it would…
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81