AlgoScope

Heap Sort

AlgorithmintermediateSorting

Build a max-heap in place, then repeatedly swap the root to the end of the shrinking heap and sift the new root down.

Decision · step 2 of 26Heap Sort: Eight values
heap 0-740101325314857627ichild2 < 5

Index 3 holds 5; its larger child is 2 at index 7. 5 is already at least as large, so the heap property holds here.

Open in the player →or start at step 2

What you will see

Heap view and array view together; the root swaps to the end and the heap shrinks by one.

How heap sort works →

Cost

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(1)

Properties

  • ✓ comparison based
  • × stable
  • ✓ in place
  • × adaptive
  • × online

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, compare two runs.

Screen readers: Cells announce index, value and state (comparing, swapped, sorted); each step announces the comparison outcome and any move.

Reduced motion: Swaps become value crossfades with outline flashes; sorted-region growth is a static span change.

Leads to

Topics that need this one first.