MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / union

Method union

graphs/boruvka.py:68–81  ·  view source on GitHub ↗

Union finds the roots of components for two nodes, compares the components in terms of size, and attaches the smaller one to the larger one to form single component

(self, component_size: list[int], u_node: int, v_node: int)

Source from the content-addressed store, hash-verified

66 self.m_component[k] = self.find_component(k)
67
68 def union(self, component_size: list[int], u_node: int, v_node: int) -> None:
69 """Union finds the roots of components for two nodes, compares the components
70 in terms of size, and attaches the smaller one to the larger one to form
71 single component"""
72
73 if component_size[u_node] <= component_size[v_node]:
74 self.m_component[u_node] = v_node
75 component_size[v_node] += component_size[u_node]
76 self.set_component(u_node)
77
78 elif component_size[u_node] >= component_size[v_node]:
79 self.m_component[v_node] = self.find_component(u_node)
80 component_size[u_node] += component_size[v_node]
81 self.set_component(v_node)
82
83 def boruvka(self) -> None:
84 """Performs Borůvka's algorithm to find MST."""

Callers 3

boruvkaMethod · 0.95
jaccard_similarityFunction · 0.45
partition_graphFunction · 0.45

Calls 2

set_componentMethod · 0.95
find_componentMethod · 0.95

Tested by

no test coverage detected