Path compression upon union in DSU

Revision en1, by bloodoath, 2022-08-17 11:12:07

Given, two disjoint sets with roots 1 and 6 respectively which already have their childrens' paths compressed.

I wish to do a union but instead of

this

I want

this

Unable to figure out a way to do this optimally.

DSU I am using is on cp-algorithms

Tags dsu

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English bloodoath 2022-08-17 11:12:07 583 Initial revision (published)