Sorting Algorithms Visualizer

About Heap Sort

Heap Sort is an efficient, in-place sorting algorithm that uses a heap data structure. It works by first building a max heap from the input array, then repeatedly extracting the maximum element and placing it at the end of the array. The result is a sorted array in O(n log n) time.

Core Concepts

  • Heap-based: Uses a binary heap data structure
  • In-place: Requires O(1) additional space
  • Not stable: May change relative order of equal elements
  • Time Complexity: O(n log n) in all cases (guaranteed performance)
  • Best for: Worst-case O(n log n) guarantee, memory-constrained environments

Heap Sort is particularly useful when you need guaranteed O(n log n) performance, unlike QuickSort which has O(n²) worst case. The heapify process organizes elements into a complete binary tree structure.

Visualization

Pseudocode

Algorithm

                            
Statistics
  • Comparisons: 0
  • Swaps: 0
  • Operations: 0

Controls

Playback