Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

Students also viewed these Databases questions

Question

Explain how HRD may be implemented

Answered: 1 week ago