HeapSort Visualization

Loading...

How HeapSort Works

HeapSort is an efficient comparison-based sorting algorithm that uses a binary heap data structure. It has two main phases:

  1. Heap Construction: Builds a max heap from the input data where the largest element is at the root.
  2. Sorting Phase: Repeatedly extracts the maximum element from the heap and rebuilds the heap with remaining elements.

Time Complexity: O(n log n) in all cases (best, average, and worst).

Space Complexity: O(1) auxiliary space (in-place sorting).

heap.html Displaying heap.html.