GoalScope — min_heap (Qwen2.5-Coder-32B-Instruct) — hover a token to see the patched verbalization
↵
<code>↵
class MinHeap:↵
"""Min Heap class implementation"""↵
def __init__(self):↵
self.heap = []↵
↵
def insert(self, element):↵
self.heap.append(element)↵
self._sift_up(len(self.heap) - 1)↵
↵
def extract_min(self):↵
if not self.heap:↵
return None↵
if len(self.heap) == 1:↵
return self.heap.pop()↵
root = self.heap[0]↵
self.heap[0] = self.heap.pop()↵
self._sift_down(0)↵
return root↵
↵
def heapify(self, arr):↵
self.heap = arr[:]↵
n = len(self.heap)↵
for i in range(n // 2 - 1, -1, -1):↵
self._sift_down(i)↵
↵
def _sift_up(self, index):↵
parent_index = (index - 1) // 2↵
if index > 0 and self.heap[index] < self.heap[parent_index]:↵
self.heap[index], self.heap[parent_index] = self.heap[parent_index], self.heap[index]↵
self._sift_up(parent_index)↵
↵
def _sift_down(self, index):↵
smallest = index↵
left_child = 2 * index + 1↵
right_child = 2 * index + 2↵
if left_child < len(self.heap) and self.heap[left_child] < self.heap[smallest]:↵
smallest = left_child↵
if right_child < len(self.heap) and self.heap[right_child] < self.heap[smallest]:↵
smallest = right_child↵
if smallest != index:↵
self.heap[index], self.heap[smallest] = self.heap[smallest], self.heap[index]↵
self._sift_down(smallest)↵
</code>