Heap Sort (Implementation)
(Reading time: 3 minutes)
To make a heap out of an array, we first need to go over all the items in the array, from right to left. This is necessary, as we start at the leaves. It receives the array we want to sort, and invokes the function that makes a heap on every element.
Press + to interact
function makeHeap(arr) {const n = arr.length;for (let i = Math.floor(n / 2) - 1; i >= 0; i--) {// Heapify function.}}
The heapify function should receive the array, the length of the array, and the current index. In order to make the heap, this order is very ...
Access this course and 1400+ top-rated courses and projects.