Question: delection/max extraction in max heap to write the pseudo code for a function that extracts the element with maximum value from a max heap,
delection/max extraction in max heap to write the pseudo code for a function that extracts the element with maximum value from a max heap, removes that element from the array, restores the array to a max heap, and returns the extracted maximum value in a variable max. Using the pseudo code as guidance, write python code to implement this deletion/max extraction algorithm in the code cell below. You can test your code using the input max-heap array A = [9, 7, 6, 5, 4, 1, 2]. Hint: if your code is correct, the returned max value should be 9, and the restored max heap (after deleting the element with max value) should be [7, 5, 6, 2, 4, 1] [ ] # please write your code for Task 5 in this code cell. Extra Credit Task 6. (bonus 1 point) Implement an algorithm that sorts all elements in an array using max heap or min heap data structure. Hint. you can use existing functions above, e.g. build_max_heap, heap_extract_max, or similar functions using min heap to implement the sorting algorithm. Test the correctness of your code using the input array A = [2,7,1,5,4,9,6]. If your code is correct, the function should return an array that has its elements sorted, either from smallest to largest or from largest to smallest. Print the returned sorted array to verify correctness. [ ] # please write your code for Task 6 in this code cell.
Step by Step Solution
There are 3 Steps involved in it
Heres a Python implementation of the function that extracts the element with the maximum value from ... View full answer
Get step-by-step solutions from verified subject matter experts
