Question: Code: import random class Sorts: def heapSort(self, array): Sorts the given array using the heapSort algorithm. Args: array: The array to sort. Returns: The

Code:
import random
class Sorts:
def heapSort(self, array):
"""
Sorts the given array using the heapSort algorithm.
Args:
array: The array to sort.
Returns:
The sorted array.
"""
# Build the heap.
for i in range(len(array) // 2, -1, -1):
self.heapify(array, i)
# Heap sort the array.
for i in range(len(array) - 1, 0, -1):
array[0], array[i] = array[i], array[0]
self.heapify(array, 0)
Error Messages:
Implement a fast sorting algorithm as described is some example code to use as a guideline. . Here You need only implement the sorting algorithm; the main method will be provided for you. You must hand in the Sorts class with the heapSort sorting algorithm implemented. This is the only file you should hand in. The heading of the method is as in the provided file. Do not change it or you will lose credit!
Step by Step Solution
3.38 Rating (160 Votes )
There are 3 Steps involved in it
Heres the implementation of the Sorts class with the heapSort algorithm class Sorts def heapifyself ... View full answer
Get step-by-step solutions from verified subject matter experts
