Heapsort is an O(n log n) sorting algorithm that uses a heap data structure represented as a balanced binary tree. It works by first heapifying an input array in O(n log n) time to create a max heap. It then repeatedly removes the maximum element from the heap, putting it in its sorted position, and sifting the new root element down to reestablish the heap property, until the heap is empty. Overall, heapsort runs in O(n log n) time like other comparison-based sorting algorithms.