CPKit
v1.6.1

Heap Sort

SortingMedium

Represent the array as a binary tree heap, extract maximums, and restore heap properties.

Alt+Shift+H

Configuration Panel

Heapification / Extract Max Visualizer

23
0
8
1
56
2
12
3
38
4
5
5
72
6
16
7
Step: 1 / 1

Time Complexity

O(N log N) for all cases (always sweeps heap trees)

Space Complexity

O(1) auxiliary space
Conceptual Overview

Heap Sort visualizes the array as a binary heap tree structure. It builds a max-heap, then repeatedly extracts the maximum element and restores the heap property.

Algorithm Idea

Phase 1: Rearrange array into a binary max heap. Phase 2: Swap the root (maximum element) with the last element. Decrease heap size and run heapify on the root. Repeat.

Stable Sorting

Unstable (heap parent swaps can reorder identical elements)

In-place Memory

In-place (sort is performed directly on the array)

Source: CP-Algorithms search & sorting reference