C Heapsort

Summary: this tutorial explains the heapsort algorithm and shows you how to implement the heapsort algorithm in C.

Introduction to the heapsort algorithm

Heapsort algorithm builds a heap from the unsorted elements, and then removes the largest element and places it at the end of a sorted array. The heap is reconstructed after each removal until there is no element left in the head and the sorted array is full.

In the worst case, the complexity of the heapsort algorithm is O(nlogn) where n is the number of elements in the unsorted list.