Question: heapsort ( da: DynamicArray ) - > None: Write a function that receives a DynamicArray and sorts its content in non - ascending order, using

heapsort(da: DynamicArray)-> None:
Write a function that receives a DynamicArray and sorts its content in non-ascending order,
using the Heapsort algorithm. You must sort the array in place, without creating any data
structures. This function does not return anything.
You may assume that the input array will contain one or more homogeneous elements
(either all numbers, or strings, or custom objects, but never a mix of these). You do not
need to write checks for these conditions.
The runtime complexity of this implementation must be O(N log N). If the sort uses an
algorithm other than Heapsort, you will not receive any points for this portion of the
assignment, even if your function passes Gradescope.
Example #1:
da = DynamicArray([100,20,6,200,90,150,300])
print(fBefore: {da})
heapsort(da)
print(fAfter: {da})
Output:
Before: DYN_ARR Size/Cap: 7/8[100,20,6,200,90,150,300]
After: DYN_ARR Size/Cap: 7/8[300,200,150,100,90,20,6]
Example #2:
da = DynamicArray(['monkey', 'zebra', 'elephant', 'horse', 'bear'])
print(fBefore: {da})
heapsort(da)
print(fAfter: {da})
Output:
Before: DYN_ARR Size/Cap: 5/8[monkey, zebra, elephant, horse, bear]
After: DYN_ARR Size/Cap: 5/8[zebra, monkey, horse, elephant, bear]

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 Programming Questions!