What is a Heap

A brief introduction to Heaps and their uses. We will also look at Heap Property and how a Heap is represented on an array.

Introduction

Heaps are advanced data structures based on Binary Trees, which is why they are commonly known as Binary Heaps.

🔍 What is a Binary Heap?

A Binary Heap is a complete Binary Tree which satisfies the Heap ordering property.

Heaps are implemented through Arrays, where each element of the array corresponds to a node in the binary tree and the value inside the node is called a “key”. Heaps can also be implemented using trees with a node class and pointers, but it’s usually easier and more space efficient to use an array.

All the nodes are ordered according to the rules listed below:

  1. A Heap tree must be a Complete Binary Tree.
  2. The nodes must be ordered according to the Heap Property.

Common Misconception

There is also a common misconception that the elements of a Heap are sorted. They are not at all sorted; in fact, the only key feature of a Heap is that the largest or smallest element is always placed at the top (parent node) depending on what kind of Heap we are using.

Moreover, this Data Structure ...

Ask