DSA Lab
Heap sort visualizer
Arrange the array as a max-heap (each parent at least as big as its children). Then swap the root, the largest, to the end and repair the heap. Repeat. When you need O(n log n) in the worst case without extra memory, as in embedded systems and the fallback inside introsort.
Heap sort: its cost, and how to use this tool
Time: best O(n log n), average O(n log n), worst O(n log n). Extra memory: O(1). Not stable, in place.
Sort a ready-made input or your own numbers. The bars are the array; the code beside them (in Python, C, C++ or Java) marks the line that just ran, and every step is explained and worked out below the bars.
Lessons that use it
- Heap sort and counting sort (Algorithms)Heap sort: O(n log n) in place. Counting sort: O(n + k) without comparing, and why comparison sorts cannot beat n log n.