What is Min Heap?
The min-heap is the heap where each and every node of a complete binary tree is less than or equal to its child node. We can see the example of a min-heap in the below image.
The above heap can be represented in an array as given below.
arr[] = {6,7,12,10,15,17};
We denote,
- “parent(i)=(i-1)/2” for the parent node.
- “left_child(i)=2*i+1” for the left child.
- “right_child(i)=2*i+2” for the right child.
Here, i is the index of the current node in the array.
For example, To find a parent of the 4th element of the array given below we use parent(4)=(4-1)/2=1th node or element at the index at 1 in an array. We are going to use these three formulas in the implementation of the min heap.
C Program to Implement Min Heap
In this article, we will learn the implementation of min heap in C programming language.
A heap is a data structure like a tree with some special properties. The basic requirement of the heap is that the value of a node must be greater than equal to (or smaller than equal to) the value of its children and the tree should be a complete binary tree.
Contact Us