MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / find_set

Method find_set

graphs/minimum_spanning_tree_kruskal2.py:26–31  ·  view source on GitHub ↗
(self, data: T)

Source from the content-addressed store, hash-verified

24 self.map[data] = DisjointSetTreeNode(data)
25
26 def find_set(self, data: T) -> DisjointSetTreeNode[T]:
27 # find the set x belongs to (with path-compression)
28 elem_ref = self.map[data]
29 if elem_ref != elem_ref.parent:
30 elem_ref.parent = self.find_set(elem_ref.parent.data)
31 return elem_ref.parent
32
33 def link(
34 self, node1: DisjointSetTreeNode[T], node2: DisjointSetTreeNode[T]

Callers 2

unionMethod · 0.95
kruskalMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected