Question: python pls! class MinHeap: def __init__(self, length): Creates heap array with length empty slots, initialized to None. Array length should never change. pass def insert(self,

 python pls! class MinHeap: def __init__(self, length): """Creates heap array with

python pls!

class MinHeap: def __init__(self, length): """Creates heap array with length empty slots, initialized to None. Array length should never change.""" pass

def insert(self, value): """Takes numeric value as argument. Returns nothing. Inserts value into heap using upheap algorithm. If heap has no empty slots remaining, do nothing.""" pass

def extract_min(self): """Takes no arguments. Removes and returns min value in heap using downheap algorithm. If heap is empty, return None.""" pass

def get_heap_array(self): """Takes no arguments. Returns internal heap array for automated grading tests.""" pass

Your code must be in a file called heap.py. Your heap implementation must be in a class called MinHeap. Starter code is attached to this assignment. You must use a Python built-in list (which is an array) for the heap. The heap array should never change its length after it's initialized. Your Min Heap class should have these methods: _init_(length): Takes the heap array length as an argument. Initializes the heap as a Python built-in list with length empty slots, initialized to None. insertivalue): Takes a numeric value as an argument and returns nothing. Inserts the value into the heap, using the upheap/percolate-up algorithm. o If the heap array has no empty slots remaining, return without doing anything. Duplicate values are allowed and should be inserted normally. extract_mino: Takes no arguments. Removes and returns the minimum value from the heap using the downheap/percolate-down algorithm. If heap is empty, return None. get_heap_array(): Takes no arguments and merely returns the internal heap array. This method is for our automated grading tests. Here's an example of how your MinHeap should work: 8 length values = [1, 6, 7, 3, 1, 10, 6] hear Minileap (length) prinl.(heap.cel. heap array()) [None, None, None, None, None, None, None, None] tor value in values: heao.inserlivalue) print (heap.got_heap_array()) ! 1-3, 6, 6, 18, 44, 10, 7, Nonel prinL (heap.exLiaonin()) # - 3 print (heap.get_heap_array() + [6, 7, 5, 13, 44, 10, None, None]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!