In computer science, heapsort is a comparison-based sorting algorithm. Heapsort can be thought of as an improved Selection sort: like selection sort, heapsort divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element from it and inserting it into the sorted region. Unlike selection sort, heapsort does not waste time with a linear-time scan of the unsorted region; rather, heap sort maintains the unsorted region in a Heap Data structure to more quickly find the largest element in each step.

## Algorithm

- Create a heap which is ordered as you’d like to sort the list (e.g. Min heap property or Max heap property) from all elements in the list to be sorted
- Swap the first element in the list (the top of the heap) with the last element
- Limit the heap’s scope to not include the recently swapped element
- Heapify
- Goto step 2 unil the list is sorted

## Implementation

Heapsort implementation in python

## Bibliography

“Heapsort.” 2022.

*Wikipedia*, September. https://en.wikipedia.org/w/index.php?title=Heapsort&oldid=1110069153.