Heap sort is a comparison-based sorting algorithm. It works by repeatedly removing the maximum value from the heap and placing it at the end of the array, while maintaining the heap property.
Start by building a heap from the input array. This involves repeatedly adding elements to the heap until it is full.
Read more about forming the heap
Heapify the heap by repeatedly removing the maximum value from the root and placing it at the end of the array. This is done by swapping the root with the last non-leaf node in the heap.
Read more about heapifying the heap
Repeat steps 1-2 until the heap is empty.
Read more about optimizing the algorithm