JavaScript Algorithms and Data Structures: Sorting - Heap Sort

Heap sort is a sorting algorithm that works by building a heap data structure and then repeatedly removing the maximum element from the heap. Learn how to implement heap sort in JavaScript.

Heapsort is a comparison-based sorting algorithm. Heapsort can be thought of as an improved selection sort: like that algorithm, it divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. The improvement consists of the use of a heap data structure rather than a linear-time search to find the maximum.

Algorithm Visualization

Algorithm Visualization

Complexity

NameBestAverageWorstMemoryStableComments
Heap sortn log(n)n log(n)n log(n)1No 

References

Wikipedia

The Original Article can be found on https://github.com/

#javascript #algorithms #datastructures #sorting

JavaScript Algorithms and Data Structures: Sorting - Heap Sort
2.60 GEEK