Skip to content
DSA Visualizerpreview

Heap sort

Build a max-heap in the array, then keep moving its top to the end.

O(n log n) time · O(1) space

Values4, 10, 3, 5, 1, 8, 7

Start with 4, 10, 3, 5, 1, 8, 7. First build a max-heap: every parent at least as big as its children.

Array of 7 values: 4, 10, 3, 5, 1, 8, 7.
  • compare
  • swap or write
  • settled

1 / 25

Speed

Space play · ← → step · Home End jump · drag the strip to scrub