Heapsort is an efficient in-place comparison based sorting algorithm with O(N log N) time complexity and uses a data structure to achieve it. It uses a complete Binary Heap data structure to sort the elements depending on whether the heap is Min Heap (ascending) or Max heap (descending).