**Heap**

The Heap data structure is an array object that can be viewed as a complete and balanced binary tree. Min (Max)-Heap has a property that for every node other than the root, the value of the node is at least (at most) the value of its parent. Thus, the smallest (largest) element in a heap is stored at the root, and the sub-trees rooted at a node contain larger (smaller) values than does the node itself.

A Min-heap viewed as a binary tree and an array. Heaps can be used as an array. For any element at array position I, left child is at ( 2i ), right child is at ( 2i+1 ) and parent is at (int) (i / 2). Heap size is stored at index 0.

Basic operations of a heap are:

1. Insert – Insert an element.

2. Delete minimum – Delete and return the smallest item in the heap.

**Performance**

1. Worst case complexity of Insert is O (lg n), where n is the number of elements in the heap.

2. Worst case running time of DeleteMin is O (lg n) where n is the number of elements in the heap.

**Complete Tutorial with Example :**