Question: def extract min(self): if (self.is empty)): raise EmptyHeapException (Heap is empty) min-value self-heap[0] 1_node-self._heap.pop (len(self._heap) if(len(self.-heap) != 0): -1) self-heap[0] = 1-node self.downheap_bubbling) return min

![min-value self-heap[0] 1_node-self._heap.pop (len(self._heap) if(len(self.-heap) != 0): -1) self-heap[0] = 1-node self.downheap_bubbling)](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f2f10360407_44366f2f103137a0.jpg)
def extract min(self): if (self.is empty)): raise EmptyHeapException ("Heap is empty") min-value self-heap[0] 1_node-self._heap.pop (len(self._heap) if(len(self.-heap) != 0): -1) self-heap[0] = 1-node self.downheap_bubbling) return min value def downheap_bubbling(self): while (self.vioates (cur)): child index -self.find_index(cur) self..heaplcur] , self.-heap[child-index) cur childindex self.-heaplchild-index) self.-heaplcur] , - def violates(self, index): left Index * 2 + 1 right- index 2 + 2 violatesTrue if (left >= len(self-heap)): violates False violates violates elif (right >- len(self._heap)): self-heap[index] > self-heaplleft] else: (self-heaplindex) self.-heaplleft]) or (self-heaplindex) > self.-heaplright)) . return violates def find index(self, index): left Index * 2 + 1 right- index 2 + 2 returned index = 0 if (right - len (self._heap)): returned index1eft (self-heaplleft] ? self-heap[right]): returned index = left elif else: returned-index return returned_index right
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
