Arrays - Heap Sort
Heap Sort is an efficient, comparison-based sorting algorithm based on a binary heap data structure. Heap Sort builds a max-heap from the array and then repeatedly extracts the maximum element to achieve the sorted order. It is particularly effective for sorting large datasets due to its time complexity.
Video Explanation

Algorithm Steps
- Build a Max-Heap: Start by building a max-heap from the input array.
- Heap Sort Process:
- Swap the root of the heap (maximum element) with the last element in the array.
- Reduce the size of the heap and call
heapifyon the root to restore the max-heap property. - Repeat this process until the heap size is reduced to 1.
- Final Sorted Array: The array will be sorted in ascending order as a result.