Heap sort visualizes the array's elements as a special type of complete binary tree known as a heap. It is similar to the selection sort in that we first identify the minimal element and set it at the beginning. It follows the same procedure for the remaining items.
This occurs when no sorting is necessary, implying that the array is already sorted. The best-case time complexity for heap sort is O(n logn).
This arises when the array elements are jumbled and do not appropriately climb or descend. The average time complexity of a heap sort is O(n log n).
This occurs when array members must be sorted in reverse order. That is, assume you need to sort the array elements in ascending order but the elements are in descending order. The worst-case time complexity for heap sort is O(n log n).
The space complexity is O(1) since we have a set amount of variables and do not require any more memory space other than the loop variables and auxiliary variables such as temp, n, index, and biggest.