Binary Heap:

Binary Heap is a Binary Tree with following properties

– It’s a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array.

– A Binary Heap is either Min Heap or Max Heap. In a Min Binary Heap, the key at root must be minimum among all keys present in Binary Heap. The same property must be recursively true for all nodes in Binary Tree.

Max Binary Heap is similar to Min Heap

For Array Binary

– If parent is at ith position then

– – Left child will be at 2*i + 1

– – Right child will be at 2*i + 2

– If a child is at ith position then,

– – Parent will be at i / 2

Latest Source Code:

Github: ArrayBinaryHeap.java

**Output:**

[3, 5, 7, 6, 20, 10, 8, 12] Extract Min: 3 [5, 6, 7, 12, 20, 10, 8, null] Extract Min: 5 [6, 8, 7, 12, 20, 10, null, null] Extract Min: 6 [7, 8, 10, 12, 20, null, null, null] Extract Min: 7 [8, 12, 10, 20, null, null, null, null] Extract Min: 8 [10, 12, 20, null, null, null, null, null] Extract Min: 10 [12, 20, null, null, null, null, null, null] Extract Min: 12 [20, null, null, null, null, null, null, null] Extract Min: 20 [null, null, null, null, null, null, null, null]