union find
TRANSCRIPT
![Page 1: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/1.jpg)
UNION - FIND
ALGORITHM
![Page 2: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/2.jpg)
Union Find problem and a set of algorithms for solving it
Dynamic connectivityQuick find algorithmQuick union algorithmImprovementsApplications
![Page 3: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/3.jpg)
![Page 4: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/4.jpg)
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 !
![Page 5: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/5.jpg)
![Page 6: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/6.jpg)
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].
![Page 7: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/7.jpg)
![Page 8: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/8.jpg)
![Page 9: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/9.jpg)
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.
![Page 10: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/10.jpg)
![Page 11: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/11.jpg)
![Page 12: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/12.jpg)
![Page 13: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/13.jpg)
![Page 14: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/14.jpg)
![Page 15: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/15.jpg)
![Page 16: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/16.jpg)
![Page 17: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/17.jpg)
![Page 18: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/18.jpg)
![Page 19: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/19.jpg)
![Page 20: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/20.jpg)
![Page 21: Union find](https://reader036.vdocument.in/reader036/viewer/2022062406/55c3d144bb61ebba538b4734/html5/thumbnails/21.jpg)
THANK YOU