# HEAP In Data Structure/ Where is heap used in data structure?

Hello Friends, In this blog post(HEAP In Data Structure) I am going to let you know about an interesting topic that is a heap.

Inside this blog post, we are going to cover What is a heap with an example? Where is heap used in the data structure? What is Max heap in the data structure? What is heap size in heap sort?

### What is a heap with an example?

Heap is known as a tree-based data structure and all the nodes in the tree are in a specific order.

The term heap can be defined as follows- A heap of size n is a binary tree of n nodes that satisfies the following two constraints:

The binary tree is almost complete which means there is an integer such that every leaf of the tree is at level k or k+1 and if a node has a right descendent at level k+1 then that node also has a left descendent at level k+1.

The keys in the nodes are arranged such that the content of each node is less than or equal to the contents of its father. This means for each node info[i]<= info[j] where j is the father of node i.

This condition means that the level of the heap is filled left to right and that a node is not placed on a new level until the preceding level is full. All the binary trees in fig 1 are heaps.

### Where is heap used in the data structure?

Heap is a tree-based data structure and is used in many popular algorithms like Dijkstra’s algorithm for finding the shortest path, Heap sort sorting algorithm, implementing the priority queue and etc.

### What is Max heap in the data structure?/ What is Min heap in data structure?

Both the heap trees are constructed based on the input and arrival order. Min heap is a tree where the value of the root node is less or equal to either of the children.

Whereas the Max heap is a tree where the value of the root node is greater or equal to either of the children.

### What is heap size in heap sort?

Using the length function we can discover the size of an array or the number of elements present in the array whereas heap size is the number of elements…

… in the sorted order. And we can also say that heap size is the number of elements that follow the heap properties.

## Conclusion:

Using this blog post we have gone through What is a heap with an example, Where is heap used in the data structure, What is Max heap in the data structure, What is heap size in heap sort, Min heap.

In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.

Hope! you would have enjoyed this post about heap.

Please feel free to give your important feedback in the comment section below.

Have a great time! Sayonara!