Heap Sort
A comparison-based sorting algorithm that uses a Binary Heap data structure. It divides its input into a sorted and an unsorted region, and iteratively shrinks the unsorted region by extracting the largest element.
Heap Sort
A comparison-based sorting algorithm that uses a Binary Heap data structure. It divides its input into a sorted and an unsorted region, and iteratively shrinks the unsorted region by extracting the largest element.
Starting Heap Sort
Sort with a heap
Order the steps of in-place heap sort.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
Test your knowledge
What is the "Heap Property" in a Max Heap?
The short version
Think of a corporate hierarchy where the boss (largest number) is always at the top. To sort, you repeatedly 'retire' the boss and promote the next best candidate to the top position.
In more depth
Structure from Chaos
Heap Sort turns the array into a Binary Heap first. This structure allows us to efficiently pull out the largest (or smallest) element repeatedly.
The Process:
Why use it?
It combines the best of both worlds: the O(n log n) guarantee of Merge Sort and the O(1) space efficiency of Quick Sort. However, it is not stable and generally slower in practice due to poor cache locality.
When to reach for this
- When **O(1) Space** complexity is a strict requirement
- When you need guaranteed **O(n log n)** time complexity
- Embedded systems or environments with limited memory
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required