Playground

Heap Sort

Observe max-heap construction and element extraction with a dual tree and array view.

Heap Sort

Push every element into a Min-Heap, then pop them out one by one, the heap always gives you the smallest element first. Explore how the heap works →

Time O(n log n)  |  Space O(n)  |  Not Stable  |  Priority Queue-based
Data
Size7
Speed900ms
Pushed0
Popped0
n7
Input Array
38
27
43
3
9
82
10
Items stored0
Always emits minimumawaiting push…
push O(log n) · pop O(log n)
Sorted Output
awaiting pop…

HEAP SORT

heapSort(arr):
heap ← MinHeap()
for val in arr:
heap.push(val) // O(log n)
sorted ← []
while heap ≠ ∅:
sorted.append(heap.pop()) // O(log n)
return sorted

Console

n = 7
>Press SORT to begin…