(self, parent, rank, x, y)
| 17 | return self.find(parent, parent[i]) |
| 18 | |
| 19 | def apply_union(self, parent, rank, x, y): |
| 20 | xroot = self.find(parent, x) |
| 21 | yroot = self.find(parent, y) |
| 22 | if rank[xroot] < rank[yroot]: |
| 23 | parent[xroot] = yroot |
| 24 | elif rank[xroot] > rank[yroot]: |
| 25 | parent[yroot] = xroot |
| 26 | else: |
| 27 | parent[yroot] = xroot |
| 28 | rank[xroot] += 1 |
| 29 | |
| 30 | # Applying Kruskal algorithm |
| 31 | def kruskal_algo(self): |