algo·visual

Heap Sort

Sorting
avgO(n log n)worstO(n log n)spaceO(1)
692355201377315629698033272364
69
23
55
20
13
77
31
56
29
69
80
33
27
23
64

Treat the 15 values as a complete binary tree

1 / 129
Size15
Distribution
Custom values2 to 150 whole numbers, each 1 to 999

seed 17

How it works

Arranges the array as a binary max-heap, then repeatedly swaps the root (the maximum) to the end and sifts the new root down to restore the heap. It sorts in place in O(n log n) every time, but it isn't stable.

Complexity

Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(1)
Stable
No
In place
Yes

Search algorithms

Jump to any algorithm or page