Questions tagged [disjoint-union]
55 questions
2
votes
1 answer
Algorithm for searching the disjoint union on dependency graph
First of all, some context about the problem:
I´m working in a system that has several types of resources (A, B, C...). I am given some resources requirements and I need to determine if I can afford them.
For this, I have some sources, each one can…

Evans
- 1,589
- 1
- 14
- 25
1
vote
0 answers
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 working for some test cases.
void make(int item)
{
…

Xiao
- 21
- 1
- 4
1
vote
1 answer
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 solution proceeds as
initialise each vertex's…

Suniti Jain
- 382
- 2
- 10
1
vote
1 answer
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 parent[v] = find_set(parent[v]);?
usually the…

Marcello Faria
- 27
- 4
1
vote
2 answers
How to properly implement disjoint set data structure for finding spanning forests in Python?
Recently, I was trying to implement the solutions of google kickstater's 2019 programming questions and tried to implement Round E's Cherries Mesh by following the analysis explanation.
Here is the link to the question and the…

user24071
- 13
- 4
1
vote
1 answer
Refining typescript disjoint union
I am trying to get something like the following to work, however typescript is outputting errors on trying to access the o.foo property:
type Base = { s: string };
type Extra = { foo: string; };
type Other = { bar: string; };
type T = Base & (Extra…

AHM
- 5,145
- 34
- 37
1
vote
4 answers
disjoint unions in C,Pascal and SML
I was studying about disjoint unions in programming. I came across with the saying that Pascal,SML and C have their own union version: variant record,construction and union. It was also saying that Pascal contains a "tag" that you don't have to use…

vesii
- 2,760
- 4
- 25
- 71
1
vote
1 answer
Which approach is best Bfs or Dfs or Disjoint set for finding all disconnected graphs
Which approach should we use to find all disconnected graphs and why ?
As BFS and DFS traversal both are traversal methods and by multiple traversals. We can find all disconnected components.
And another approach can be Disjoint Sets as used in…

Aadish Goel
- 451
- 1
- 4
- 12
1
vote
2 answers
c# most efficient way to extract non-overlapping sorted ranges
In order to highlight multiple search text elements in a single string, I have a routine computing the ranges to be highlighted within the string itself.
For example, if I search his+is string in string "this is my misk test" I get higlighted ranges…

neggenbe
- 1,697
- 2
- 24
- 62
1
vote
1 answer
Tagged unions in closure compiler
I'm currently in the process of comparing the Google Closure Compiler and the Flow static type checker, in terms of expressiveness. What I like about the latter is that it apparently can represent tagged unions quite nicely. The manual gives this…

MvG
- 57,380
- 22
- 148
- 276
1
vote
2 answers
In search of the proper Union DST with inverse-ackermann complexity
I am talking about the union-find-disjoint data structure. There are multiple resources on the internet about how to implement this. So far, I have learnt of two optimization techniques for unions. The first one is 'balancing' the tree by a variable…

ReaLNero
- 31
- 5
0
votes
1 answer
Disjoint union-find analysis
In disjoint union suppose we have to merge two trees whose heights are respectively h1 and h2. Using this technique, the height of the resulted merged tree will be max(h1, h2) if h1 not equal to h2, or h1+1 if h1 == h2. Using this technique after…

venkysmarty
- 11,099
- 25
- 101
- 184
0
votes
0 answers
Disjoint Union of Strings
I have a vector of vector of strings of size == 2 with the following format
vector> equations;
where equations[i]={"Hi", "I am"};
I want to make a disjoint union of the two strings "Hi" and "I am" for all the values of i.
So I tried…

Xiao
- 21
- 1
- 4
0
votes
0 answers
Does specifying a representative of DSU affect its time complexity?
I read Tarjan's offline LCA algorithm on CLRS, Page 584, and found an operation find-set(u).ancestor = u to force the representative of the set to be u. I wonder whether this operation will break the Disjoing union's structure.
To achieve the best…

hjmu
- 1
- 1
0
votes
1 answer
Insert items into a list based on their occurrence
Say I am continuously generating new data (e.g. integers) and want to collect them in a list.
import random
lst = []
for _ in range(50):
num = random.randint(0, 10)
lst.append(num)
When a new value is generated, I want it to be positioned…

Shaun Han
- 2,676
- 2
- 9
- 29