Heap Sort Visualizer — Animated, Step-by-Step
Animated heap sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs in your browser.
Code examples
Ready-to-copy reference implementations. Free to use in your own projects and assignments.
How to use
- 1 Press Play to watch the array build a max-heap, then repeatedly extract the max.
- 2 Use Step to advance one sift-down comparison at a time.
- 3 Type your own numbers into Custom input and press Apply.
- 4 Follow the highlighted pseudocode and the live comparison / swap counters.
Why use this tool
- See how the array is treated as a binary heap (parent at i, children at 2i+1 / 2i+2).
- Watch sift-down restore the heap property after each max is moved to the end.
- Understand why heap sort guarantees O(n log n) with O(1) extra space.
- Runs entirely in your browser. No signup, no uploads.
Frequently asked questions
What is heap sort?
Heap sort builds a max-heap from the array, then repeatedly swaps the root (largest) to the end and sifts down to restore the heap, growing a sorted region from the right.
What is the time complexity of heap sort?
O(n log n) in the best, average, and worst case. Building the heap is O(n) and each of the n extractions costs O(log n).
Is heap sort stable?
No. Heap operations swap elements far apart, which can reorder equal values.
How does heap sort compare to quicksort?
Heap sort has a guaranteed O(n log n) worst case and uses O(1) extra space, but quicksort is usually faster in practice due to better cache locality and a smaller constant factor.
What is Heap Sort Visualizer?
A Heap Sort Visualizer animates heap sort: building a max-heap from the array, then repeatedly swapping the root to the end and sifting down to restore the heap. It demonstrates the guaranteed O(n log n) time with O(1) extra space.
Features
Step-by-step animation
Watch the max-heap build and each extract-and-sift-down step.
Complexity
Time: O(n log n) in all cases. Space: O(1). In-place; not stable.
100% private
Runs entirely in your browser — nothing is uploaded.
Example
Input
[4, 10, 3, 5, 1]
Output
build max-heap [10,5,3,4,1]; extract max repeatedly → [1, 3, 4, 5, 10] (sorted)
Common use cases
-
1
Worst-case O(n log n) in-place
See a sort that guarantees O(n log n) without O(n) extra space.
-
2
Learn the heap structure
Understand max-heaps and sift-down through the sort.
-
3
Priority-queue link
Connect heap sort to the binary-heap priority queue.
Zerethon's heap sort visualizer animates the algorithm in your browser, first building a max-heap and then repeatedly extracting the maximum to the end of the array. Heap sort runs in O(n log n) time in the best, average, and worst case, using O(1) extra space; it is in-place but not stable. It combines merge sort's worst-case guarantee with constant extra space.
- Category
- Algorithm
- Pricing
- Free
- Privacy
- Browser-based
- Signup
- Not required
References
- MIT OCW 6.006 — Introduction to Algorithms (CLRS) — MIT OpenCourseWare
- VisuAlgo — Sorting — VisuAlgo (NUS)
- Heapsort — Wikipedia
Privacy
Your data never leaves your browser unless explicitly stated. Heap Sort Visualizer runs entirely client-side — no server upload, no logging, no tracking of your input.
New to this? Read the step-by-step explanation with Big-O analysis: Learn Sorting Algorithms →
Compare
Related tools
Bubble Sort Visualizer
Animated bubble sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs entirely in your browser.
Open toolInsertion Sort Visualizer
Animated insertion sort with step controls, speed, custom input, live comparison/write counters and pseudocode. Runs in your browser.
Open toolSelection Sort Visualizer
Animated selection sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs in your browser.
Open toolMerge Sort Visualizer
Animated merge sort with step controls, speed, custom input, live comparison/write counters and pseudocode. Runs in your browser.
Open toolBuild, share, and grow on Zerethon Social
Free signup. Earn points, collect achievements, and connect with creators worldwide.