Skip to content

Commit 9563b1c

Browse files
author
cureprotocols
committed
Refactor: renamed union() parameters for descriptive clarity
1 parent 8991be0 commit 9563b1c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Diff for: data_structures/disjoint_set/union_find.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Author: Michael Alexander Montoya
1212
"""
1313

14-
1514
class UnionFind:
1615
def __init__(self, size: int) -> None:
1716
"""
@@ -36,9 +35,9 @@ def find(self, node: int) -> int:
3635
self.parent[node] = self.find(self.parent[node]) # Path compression
3736
return self.parent[node]
3837

39-
def union(self, a: int, b: int) -> bool:
38+
def union(self, node_a: int, node_b: int) -> bool:
4039
"""
41-
Unites the sets that contain elements `a` and `b`.
40+
Unites the sets that contain elements `node_a` and `node_b`.
4241
4342
>>> uf = UnionFind(5)
4443
>>> uf.union(0, 1)
@@ -48,13 +47,12 @@ def union(self, a: int, b: int) -> bool:
4847
>>> uf.union(0, 1)
4948
False
5049
"""
51-
root_a = self.find(a)
52-
root_b = self.find(b)
50+
root_a = self.find(node_a)
51+
root_b = self.find(node_b)
5352

5453
if root_a == root_b:
5554
return False # Already connected
5655

57-
# Union by rank
5856
if self.rank[root_a] < self.rank[root_b]:
5957
self.parent[root_a] = root_b
6058
elif self.rank[root_a] > self.rank[root_b]:

0 commit comments

Comments
 (0)