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

Method _bubble_up

graphs/minimum_spanning_tree_prims2.py:134–146  ·  view source on GitHub ↗
(self, elem: T)

Source from the content-addressed store, hash-verified

132 self._bubble_down(elem)
133
134 def _bubble_up(self, elem: T) -> None:
135 # Place a node at the proper position (upward movement) [to be used internally
136 # only]
137 curr_pos = self.position_map[elem]
138 if curr_pos == 0:
139 return None
140 parent_position = get_parent_position(curr_pos)
141 _, weight = self.heap[curr_pos]
142 _, parent_weight = self.heap[parent_position]
143 if parent_weight > weight:
144 self._swap_nodes(parent_position, curr_pos)
145 return self._bubble_up(elem)
146 return None
147
148 def _bubble_down(self, elem: T) -> None:
149 # Place a node at the proper position (downward movement) [to be used

Callers 2

pushMethod · 0.95
update_keyMethod · 0.95

Calls 2

_swap_nodesMethod · 0.95
get_parent_positionFunction · 0.85

Tested by

no test coverage detected