Heapsort

Another important algorithm for sorting is called Heapsort. Heapsort uses the Heap data structure in order to sort the given array of data. Heapsort first builds a Max Heap, where each parent node is greater than the child node. Developed by J. W. J. Williams, Heapsort is a common used sorting algorithm used in place of Quicksort for its more favorable worst case. Its Big-O notation for Best Case Performance is Ω(n), O(n log n), and its Worst Case Performance is O(n log n).

To start, you build a Max Heap using the given array. Running MaxHeapify, your heap should fulfill the properties of a Max Heap, where each parent node is greater than the child node. Then, you swap the root of the heap with the size of the array- i, the size of the array times, starting at 0. After each swap decrease the heap size by one, excluding the sorted element from the heap. Run MaxHeapify again. Once the for loop finishes running, your array will be sorted from smallest to largest.