- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Array Representation Of Binary Heap

The complete binary tree that follows the properties of heap ordering is called **binary heap**.

Based on the ordering of binary heap, it can be of two types −

**min Heap** is the heap in which the value of node is greater than or equal to the value of its parent node. The root node of min heap is smallest.

**max Heap** is the heap in which the value of node is smaller than or equal to the value of its parent node. The root node of max heap is greatest.

The values of binary heap is typically represented as an **array**. The array representation of binary heap as −

Index of the root element is 0.

If i is the index of the node in the array. Then, the other nodes related to the node are index in the array as −

Left child : (2*i)+1

Right child : (2*i)+2

Parent child : (i-1)/2

Using the above rules of array representation of we can represent a heap in array −

1 | 4 | 7 | 8 | 9 | 11 | 12 |

Now, the types of heaps based on ordering can be discussed here

**Min Heap**− The root node has the minimum value. The value of node is greater than value of parent node.

Example −

Array representation −

1 | 4 | 7 | 6 | 9 | 10 | 8 |

**Max Heap**− The root node has the maximum node. The value of node is smaller than the value of parent node.

Example −

Array representation −

11 | 8 | 9 | 6 | 4 | 5 | 1 |

- Related Questions & Answers
- Memory representation of Binomial Heap in C++
- Binary Heap in Data Structure
- Binary representation of next number in C++
- Binary representation of previous number in C++
- C++ Program to Implement Binary Heap
- Binary representation of a given number in C++
- Binary Tree Representation in Data Structures
- Calculating 1s in binary representation of numbers in JavaScript
- Circular Permutation in Binary Representation in C++
- Array of Arrays Representation in Data Structure
- Prime Number of Set Bits in Binary Representation in C++
- Prime Number of Set Bits in Binary Representation in Python
- XOR counts of 0s and 1s in binary representation in C++
- Sorting according to number of 1s in binary representation using JavaScript
- Check if binary representation of a number is palindrome in Python