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

Method extract_min

graphs/minimum_spanning_tree_prims2.py:108–118  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

106 self._bubble_up(elem)
107
108 def extract_min(self) -> T:
109 # Remove and return the element with lowest weight (highest priority)
110 if self.elements > 1:
111 self._swap_nodes(0, self.elements - 1)
112 elem, _ = self.heap.pop()
113 del self.position_map[elem]
114 self.elements -= 1
115 if self.elements > 0:
116 bubble_down_elem, _ = self.heap[0]
117 self._bubble_down(bubble_down_elem)
118 return elem
119
120 def update_key(self, elem: T, weight: int) -> None:
121 # Update the weight of the given key

Callers 1

prims_algoFunction · 0.95

Calls 3

_swap_nodesMethod · 0.95
_bubble_downMethod · 0.95
popMethod · 0.45

Tested by

no test coverage detected