Union find
-
Upload
vyakhya-shrivastava -
Category
Engineering
-
view
32 -
download
1
Transcript of Union find
UNION - FIND
ALGORITHM
Union Find problem and a set of algorithms for solving it
Dynamic connectivityQuick find algorithmQuick union algorithmImprovementsApplications
There are basically two major parts in each algorithm:
-> Union Command: Connect the two objects-> Find / Connected query: Is there a path
connecting the two objects !
QUICK FIND (Eager Approach)
Data StructureInteger array id[] of size NInterpretation : p and q are connected iff they
have the same id.FindCheck if p and q have the same id.UnionTo merge components containing p and q,
change all entries whose id equals id[p] to id[q].
QUICK UNION (Lazy Approach)
Data StructureInteger array id[] of size NInterpretation: id[i] is parent of IRoot of i is id[id[id[…id[i]…]]].FindCheck if p and q have the same root.UnionTo merge components between p and q, set the
id ofp’s root to the id of q’s root.
THANK YOU