Min Heap: Introduction
Explore the fundamentals of Min Heaps, including their array implementation and the essential operations of insertion and removal. Understand how to maintain the min heap property through percolating elements up or down. This lesson equips you with practical knowledge to implement and manipulate Min Heaps efficiently in JavaScript.
We'll cover the following...
Building a Min Heap
Min heaps follow the min heap property which means that the key at the parent node is always smaller than the keys at the child nodes. Heaps can be implemented using arrays. Initially, elements are placed in nodes in the same order as they appear in the array. Then a function is called over the whole heap in a bottom-up manner that “Min Heapifies” or “percolates up” on this heap so that the heap property is restored. The “Min Heapify” function is bottom-up because it starts comparing and swapping parent-child key values from the last parent (at the ...