Question: Min heap class implementation in Python. Implement a min-using an array. Your min-heap class will have one private attribute, an array of integers. Implement the

Min heap class implementation in Python.

 Min heap class implementation in Python. Implement a min-using an array.

Implement a min-using an array. Your min-heap class will have one private attribute, an array of integers. Implement the following methods for the min-heap class You may not use the built-in min function. init - Constructor makes an empty heap str - Prints the heap out in any way you want for debugging only) makenull(self) - Makes the heap empty insert(self,x) - Insert element x into the heap parent(self,i) - Returns the index of the parent of the element at index i (p=(i-1)/2) left(self,i) - Returns the index of the left child of the element at index i (I=(i+1)*2-1 right(self,i) - Returns the index of the right child of the element at indexi (r=(i+1)*2) swap(self, a,b) - Swaps elements at indexes a and b upheap(self,i) - Upheaps starting at index i downheap(self,i) - Downheaps starting at index i inorder(self,i) - Returns a string of the tree inorder starting at index i (put spaces after each value) preorder(self,i) - Returns a string of the tree in preorder starting at index i (put spaces after each value) postorder(self,i) - Returns a string of the tree in postorder starting at index i (put spaces after each value) min(self) - returns the smallest value in heap. deletemin(self)-deletes smallest number in heap sort(self) - Print out the values, one per line, in sorted order. This command destroys the heap. A test system is provided that will test your implementation. An example execution is provided below

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!