Download to read offline









































Heap sort is a comparison-based sorting algorithm that uses a heap data structure. It works in two phases: first it builds a max heap from the input data and then extracts elements from the heap one by one, each time putting the largest remaining element in its sorted position. This results in the elements being sorted in non-decreasing order with a time complexity of O(n log n). Heap sort is an efficient in-place sorting algorithm that uses constant extra space.