Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started