Search⌘ K
AI Features

Min Heap: Introduction

Explore how to build a Min Heap by maintaining the heap property where parent nodes are smaller than child nodes. Understand insertion and removal processes, including percolating values up or down, to keep the heap organized and efficient for sorting and priority queue operations.

Building a Min-Heap

As mentioned in a previous lesson, 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 lists. Initially, elements are placed in nodes in the same order as they appear in the list. 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 ...