Heap, the data structure!

A heap is a special tree-based data structure where the tree is a complete tree or an almost complete tree which satisfy the heap property. Now, what is heap property? The heap property states that in a heap all the keys of children nodes must be greater than or equal or less than or equal of the key of the parent node. Based on the heap property there are two kinds of heaps:

Max heap

In the max heap, the key of a node is greater than or equal of all the child nodes and the key of the root is the greatest.

A max heap
Max heap

Min heap

In the max heap, the key of a node is less than or equal of all the child nodes and the key of the root is the minimum.

The min heap
Min heap

There are different types of heaps. Some of them are Binary heap, Binominal heap, Fibonacci heap, Leftist heap, K-D heap etc.

Heap is mostly used for the implementation of the priority queue.

I’m a computer science and engineering graduate. I’m passionate about learning and spread what I learn. Besides I like cooking and photography!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store