dedicated visualizer
Heap Sort
Builds a max heap and repeatedly extracts the root to produce a sorted suffix. This page keeps the runner, chart, and controls focused on a single algorithm so the walkthrough feels calmer than the overview page.
session controls
Compare this algorithm against a related one, turn on quiz mode, or keep the current state in a shareable URL.
current shareable URL
Copy the URL to preserve this exact dataset, target, compare mode, and quiz state.
browse more
Want a different problem or visual mode? Jump back to the catalog and open another dedicated page.
open catalogscenario presets
Load a focused input that reveals a specific behavior quickly instead of hand-editing every value first.
dataset controls
Use your own array, randomize a fresh one, or restore defaults. The same dataset is shared by both panels in compare mode.
Enter up to 12 integers. Values are normalized to the range 1–99 for clean visualization.
chart + counters
The visualization and the live counters stay together so each step is easier to read.
current action · build heap
current action
build heap
comparisons
0
final 24
swaps
0
final 18
sorted
0
final 8
heap size
8
final 1
steps
1 / 44
run summary
Finished in 44 steps. Final order: 1, 2, 3, 5, 6, 7, 8, 9.
comparisons
24
swaps
18
sorted
8
steps
44
current explanation
Heap sort first builds a max heap, then repeatedly extracts the largest value.
simple explanation
Turn the array into a heap so the biggest value is always at the root.
pseudocode
complexity card
best
O(n log n)
average
O(n log n)
worst
O(n log n)
space
O(1)
algorithm notes
intuition
The heap keeps the largest remaining value at the root, ready for extraction.
tradeoffs
- Guaranteed O(n log n) time.
- Not stable.
- Can have worse cache behavior than quick sort.
when to use it
Use when you want in-place O(n log n) performance with strong worst-case guarantees.
interview tips
- Explain how the heap maps onto array indices.
- Call out that the build-heap phase is O(n), not O(n log n).
what I learned building this
typed definitions
One algorithm schema now drives the catalog, counters, pseudocode, notes, and visual modes, which keeps the UI consistent as the lab grows.
replay over mutation
Precomputed steps made it much easier to synchronize explanations, metrics, quiz prompts, and scrubber playback without hidden state drifting out of sync.
portfolio framing
Shareable URL state, compare mode, and responsive layouts mattered as much as the algorithm logic because this page needs to teach clearly and still feel polished as a product.
more in this lane
Want a different take on the same problem family? These stay in the same category but change the strategy.
beginner
Bubble Sort
Repeatedly swaps adjacent out-of-order values so larger numbers drift to the end.
beginner
Selection Sort
Selects the minimum value from the unsorted suffix and places it into the next sorted slot.
beginner
Insertion Sort
Builds a sorted prefix by inserting each new value into the right gap.