Heap Sort: The Algorithm of Mildly-Used Socks

Heap sort is a comparison-based sorting algorithm. It works by repeatedly removing the maximum value from the heap and placing it at the end of the array, while maintaining the heap property.

Step 1: Create a Heap

Start by building a heap from the input array. This involves repeatedly adding elements to the heap until it is full.

Read more about forming the heap

Step 2: Heapify the Heap

Heapify the heap by repeatedly removing the maximum value from the root and placing it at the end of the array. This is done by swapping the root with the last non-leaf node in the heap.

Read more about heapifying the heap

Step 3: Repeat Steps 1-2

Repeat steps 1-2 until the heap is empty.

Read more about optimizing the algorithm

Read more about implementing heap sort in Python

Read more about heap sort bugs and bloopers