Skip to main content

Heap Sort

Builds a max heap from the array, then repeatedly extracts the maximum element to the end.

Interactive Visualization

Loading visualization…

Usage

import { heapSort } from 'athro';

const arr = [8, 3, 6, 2, 9, 1];
heapSort(arr);

Time Complexity

CaseTime ComplexityDescription
BestO(n log n)Heap construction and extraction
AverageO(n log n)Consistent heap operations
WorstO(n log n)Same structure regardless of input