Understanding heapsort algorithm


Heapsort is mostly used to sort arrays, but it can also be used to sort other list data structures. However, as it relies on the random access provided by arrays, heapsort may reduce the algorithm's efficiency. For the sake of this example, we will take an integer array and apply heapsort to it.

Algorithm

When applied to an array arr, heapsort works in two main steps, as described below.

Liking the course? Check our discounted plans to continue learning.