Questions tagged [union-find]

Questions about the abstract data structure Union-Find (also called disjoint-set) and its realizations.

Union-Find or disjoint-set is characterised by three operations:

  1. MakeSet(x) creates a new set with a single element x.
  2. Union(x,y) merges the two (disjoint) sets whose representatives are x and y, respectively.
  3. Find(x) returns the representative of the set which contains x.

Some problems can be solved by using only these operations (which are notably less powerful than full-blown sets or dictionaries). One popular example is Kruskal's algorithm for finding minimal spanning trees. Such algorithms profit from the efficient implementations we have for Union-Find.

Questions tagged with this tag should probably also have (if the question is about union-find data structures themselves) or (if it is about using union-find in an algorithm).

53 questions
19
votes
2 answers

Complexity of union-find with path-compression, without rank

Wikipedia says union by rank without path compression gives an amortized time complexity of $O(\log n)$, and that both union by rank and path compression gives an amortized time complexity of $O(\alpha(n))$ (where $\alpha$ is the inverse of the…
Drathier
  • 720
  • 1
  • 4
  • 13
12
votes
1 answer

Directed union-find

Consider a directed graph $G$ on which one can dynamically add edges and make some specific queries. Example: disjoint-set forest Consider the following set of queries: arrow(u, v) equiv(u, v) find(u) the first one adds an arrow $u→v$ to the graph,…
jmad
  • 9,578
  • 1
  • 40
  • 43
10
votes
1 answer

Runtime difference bewteen Union by Rank and Union by Size for union-find

I was studying Union Find, and according to Wikipedia, there are 2 types of union: union by rank and Union by size. My question is, what is the runtime difference between the two (if any)? Intuitively, it feels like Union by size would always be…
timg
  • 254
  • 2
  • 7
7
votes
1 answer

Why time complexity of union-find is $O(lgN)$ with only "Union by Rank"?

I'm studying time complexity of Union-Find data structure. I saw time complexity of union and find function depends on some conditions. without anything: $O(N)$ with Union by Rank: $O(\log N)$ with Path Compression: $O(\alpha(N))$ which is inverse…
molamola
  • 353
  • 2
  • 4
  • 11
6
votes
2 answers

Split-Find: maintaining dynamic graph connectivity information, under edge deletion

Is there a data structure to keep track of the connected components of a dynamic graph, when the graph might by changing by deleting edges of the graph? Let $G$ be an undirected graph. I have two operations I'd like to be able to…
D.W.
  • 167,959
  • 22
  • 232
  • 500
4
votes
1 answer

Find a graph for which Kruskal's algorithm achieves worst-case running time

I am working on a problem in which I must find a graph with edge weights on n vertices, for which Kruskal's algorithm achieves worst-case running time. I am using a UNION-FIND data structure, but with no optimisations (path compression or…
4
votes
1 answer

Question about tidy trees (Union-Find)

The following excerpt is taken from this paper, in page 3. Our new union-find-delete data structure, like most other union-find data structures, maintains the elements of each set in a rooted tree. As elements can now be deleted, not all the nodes…
Shlomiz
  • 119
  • 6
4
votes
0 answers

Data structure for identifying elements while keeping track of relation

I'm looking for a data structure representing a finite set $I$ and a $d$-relation $R \subseteq I^d$ such that the following operations can be implemented efficiently: Add a new element $i$ to $I$. Identify elements $i, j \in I$, i.e. take the…
4
votes
1 answer

Interesting applications of union-find

I've been trying to find interesting applications of union-find that are lesser known. Here are some popular algorithms based on union-find that I know: Kruskal's algorithm for MST Tarjan's off-line lowerst common ancestors (LCA) algorithm…
3
votes
1 answer

Quick union and heuristic by size

Studying Quick-Find and Quick-Union heuristic I've found clear that: with quick find trees and a union based on the size of the trees we can make a union in $T_{am}(n)=O(\log(n))$ with quick find trees and a union based on the height of the trees…
abc
  • 1,675
  • 2
  • 12
  • 22
3
votes
2 answers

How to understand the complexity of Kruskal implemented with Quick-Union by rank and path compression?

I'm trying to understand the complexity of the Kruskal algorithm implemented with the Quick-Union by rank and with the path compression. Now there is a theorem for the last structure above: The complexity of any sequence of m operations of Makeset,…
3
votes
2 answers

Union-Find with link-by-rank to represent a binary field with simple operations

I have a field $X$ of given length $n$ which is filled with zeroes in the beginning. I only need these 3 simple operations: GET_VALUE$(i)$: returns the value of $i$-th cell ($X[i]$) SET_TO_1$(i)$:basically $X[i] \leftarrow 1$ for $i < n - 1$,…
John Doe
  • 33
  • 3
3
votes
1 answer

Efficient intersection of equivalence classes

Having two equivalence relations, both as a union find data structure with the same number of elements, what is the most efficient way to find the equivalence relation that is the intersection of both relations? For example, lets have…
user3128
  • 98
  • 5
2
votes
1 answer

Time Complexity of a Union Find algorithm

I'm trying to understand the time complexity of an example algorithm. My conclusion was O(n^2) but this was considered wrong. The algorithm is as follows: input: data: array of sorted n integers input: n: size of data input: c:a positive integer…
moose0306
  • 71
  • 5
2
votes
2 answers

How can union-find algorithm be used with "real" data

In the beginning of the Princeton algorithms course the Dynamic connectivity problem is presented (quick-find, quick-union). Here is how it's described: The input is a sequence of pairs of integers, where each integer represents an object of some…
Max Koretskyi
  • 325
  • 1
  • 4
  • 14
1
2 3 4