Disjoint-Set forests in Python alternate implementation
问题 I'm implementing a disjoint set system in Python, but I've hit a wall. I'm using a tree implementation for the system and am implementing Find(), Merge() and Create() functions for the system. I am implementing a rank system and path compression for efficiency. The catch is that these functions must take the set of disjoint sets as a parameter, making traversing hard. class Node(object): def __init__(self, value): self.parent = self self.value = value self.rank = 0 def Create(values): l =