![Page 1: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/1.jpg)
MST – KRUSKAL
UNIT IV
![Page 2: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/2.jpg)
Disjoint-Set Union Problem
• Want a data structure to support disjoint sets – Collection of disjoint sets S = {Si}, Si ∩ Sj =
• Need to support following operations:– MakeSet(x): S = S U {{x}}– Union(Si, Sj): S = S - {Si, Sj} U {Si U Sj}
– FindSet(X): return Si S such that x Si
![Page 3: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/3.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
![Page 4: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/4.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 5: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/5.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 6: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/6.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 7: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/7.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1?
5
13
1725
148
21
Run the algorithm:
![Page 8: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/8.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 9: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/9.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2? 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 10: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/10.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 11: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/11.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5?
13
1725
148
21
Run the algorithm:
![Page 12: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/12.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 13: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/13.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148?
21
Run the algorithm:
![Page 14: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/14.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 15: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/15.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9?
1
5
13
1725
148
21
Run the algorithm:
![Page 16: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/16.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 17: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/17.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13?
1725
148
21
Run the algorithm:
![Page 18: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/18.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 19: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/19.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
14?8
21
Run the algorithm:
![Page 20: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/20.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 21: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/21.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
17?25
148
21
Run the algorithm:
![Page 22: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/22.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19?
9
1
5
13
1725
148
21
Run the algorithm:
![Page 23: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/23.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21?
Run the algorithm:
![Page 24: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/24.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725?
148
21
Run the algorithm:
![Page 25: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/25.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 26: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/26.jpg)
Kruskal’s Algorithm
Kruskal(){ T = ; for each v V MakeSet(v); sort E by increasing edge weight w for each (u,v) E (in sorted order) if FindSet(u) FindSet(v) T = T U {{u,v}}; Union(FindSet(u), FindSet(v));}
2 19
9
1
5
13
1725
148
21
Run the algorithm:
![Page 27: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/27.jpg)
MST
![Page 28: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/28.jpg)
MST - KRUSKAL KRUSKAL
![Page 29: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/29.jpg)
PRIM
![Page 30: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/30.jpg)
MST
![Page 31: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/31.jpg)
MST - KRUSKAL
![Page 32: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/32.jpg)
MST - PRIM
![Page 33: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/33.jpg)
MST – KRUSKAL
![Page 34: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/34.jpg)
MST –KRUSKAL
![Page 35: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/35.jpg)
TRY MST(PRIM/KRUSKAL)
![Page 36: MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =](https://reader035.vdocuments.site/reader035/viewer/2022062315/5697bfb81a28abf838c9f76b/html5/thumbnails/36.jpg)
TRY MST(PRIM/KRUSKAL)