I have been studying disjoint set data structures.
I've a query that while using union by rank & path compression together, if we skip using union by rank & assign precedence(parent) without any ranks comparison(of ranks of roots/representative element) of two sets(trees) will it affect the running time.
Though weighted-union heuristic is required while merging two sets,to append smaller set to larger one to make minimum updates as possible to point to representative element.
Union-by-rank(similar to weighted-union) is used while merging the two sets.But if we skip comparing ranks & randomly assign the precedence, it won't affect the running time??Then why do we use it..I am unable to see through it clearly ,please help me understand it if I'm wrong.
//no comparison for ranks
UNION(x,y)
x.parent=y;
genralized code
union(x,y){
if(x.rank>y.rank)
y.parent=x;
else
x.parent=y;
if(x.rank==y.rank)
y.rank=y.rank+1;
}