Heapsort is a sorting algorithm that uses a heap data structure. It has a worst-case runtime of O(n log n), which makes it generally slower than quicksort but more consistent. A heap is a balanced binary tree where each node's value is greater than or equal to its children's values. To sort an array using heapsort, the array is first converted to a max heap by sifting nodes up. Then the largest element is removed from the root and placed at the end, and the new root is sifted down to re-form the heap. This process repeats until the array is fully sorted in O(n log n) time.