DEV Community

221910304017
221910304017

Posted on

Heap Data structure

A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Generally, Heaps can be of two types:

  1. Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree.
  2. Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree. Image description

What are heaps used for?
Heaps are used in many famous algorithms such as Dijkstra's algorithm for finding the shortest path, the heap sort sorting algorithm, implementing priority queues, and more. Essentially, heaps are the data structure you want to use when you want to be able to access the maximum or minimum element very quickly.

What are the three main properties of heap?
1.Ordering. Nodes must be arranged in an order according to values. The values should follow min-heap or max-heap property.
2.Structural. All levels in a heap should be full.
3.Methods or Operations of Heap. find - in order to find an item in a heap.
4.Implementation. Heaps are usually implemented in an array.

Discussion (0)