Wednesday, March 3, 2021

Binary Heap properties

 A Binary Heap is a Binary Tree with following properties.

1) 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.

2) 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 MinHeap.

  • Arr[(i-1)/2]Returns the parent node
    Arr[(2*i)+1]Returns the left child node
    Arr[(2*i)+2]Returns the right child node

  • Arr[(n/2) .... (n-1)] => will contain the leaf nodes, if n is the length of the array or total number of nodes.

    The traversal method use to achieve Array representation is Level Order

    Source: geeks for geeks

No comments:

Post a Comment