Algorithm Identifying

Revision en1, by aarshee, 2015-06-14 17:12:11

What is the algorithm for merging two different sets ?

inline int find(int x){ return (parent[x] == x ? x : find(parent[x])); }

inline bool merge(int x, int y){ x = find(x); y = find(y); if(x == y) return false; if(r[x] > r[y]) x = y + x — (y = x); parent[x] = y; if(r[x] == r[y]) r[y]++; return true; }

Thanks in advance.

Tags algorithms, sets, merge-find set

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English aarshee 2015-06-14 17:12:11 374 Initial revision (published)