Intermediate 25 min

Interactive Visualization

Watch heap sort work in real-time. The visualizer shows heap building and extraction.

Heap Sort Visualization

1x

What to Observe

As you watch the visualization, notice:

  1. Build heap: Array is converted to max heap
  2. Extract max: Root (maximum) is extracted
  3. Swap: Max is swapped with last element
  4. Heapify: Heap property is restored
  5. Repeat: Process continues until sorted

Understanding the Colors

  • Orange/Yellow: Root (maximum element)
  • Green: Elements in heap
  • Blue: Elements being compared
  • Red: Elements being swapped
  • Purple: Sorted portion

Try Different Arrays

The visualizer shows how heap sort:

  • Always builds a max heap first
  • Extracts maximum elements systematically
  • Maintains heap property throughout
  • Guarantees O(n log n) performance

What’s Next?

Now that you’ve seen it work, let’s implement heap sort in code.