Heapsort is a sorting algorithm that relies on the properties of heap data structures to function correctly. It has a time complexity of and a space complexity of .
If we define an extract max function:
Then we can define the heapsort algorithm:
Since Build-Max-Heap
has a time complexity of , and