Heap Sort Visualizer

Watch how Heap Sort builds a binary max heap and repeatedly extracts the maximum element to create a sorted array.

Time: O(n log n)
Space: O(1)
Stable: No
In-place: Yes
Fast (500ms)Slow (3000ms)
Progress: Step 1 of 0Phase: start | Heap Size: 7

Array Representation

640
341
252
123
224
115
906

Binary Heap Tree

64
34
25
12
22
11
90
Heap Elements
Max Element
Current Root
Child Nodes
Comparing
Swapping
Outside Heap
Sorted

Current Step:

Click Start to begin the Heap Sort visualization

Algorithm Details

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

When to Use Heap Sort

  • Guaranteed O(n log n) time complexity needed
  • Memory-constrained environments (O(1) space)
  • When worst-case performance matters
  • Finding k largest/smallest elements
  • When stability is required
  • Small datasets (overhead of heap building)

Real-world Applications

  • Priority queues implementation
  • Operating system task scheduling
  • Graph algorithms (Dijkstra's, Prim's)
  • Finding top K elements in large datasets
  • Memory-critical embedded systems