INDEX | HOME

HeapSort

This algorithm has low memory usage like quicksort, with a better worst-case performance.

First we must re-arrange the array elements into a "Binary Max-Heap".

This is a type of binary tree stored in an array, meeting the following rules:

Then we repeatedly:

Build the Binary Max-Heap

Sort

Copyright 2026 Joseph Graham (joseph@xylon.me.uk)