Skip to content
Related Articles

Related Articles

Applications, Advantages and Disadvantages of Heap

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 06 Sep, 2022
Improve Article
Save Article

Heap is a special tree-based data structure where the tree is always a complete binary tree. Heaps are of two types: Max heap and Min heap. In the case of the max-heap, the root node will have a higher value than its subtree, and for the min-heap, the root node will have a lower value than its subtree.

Operations of Heap:

  • Heapify: a process of creating a heap from an array.
  • Insertion: process to insert an element in existing heap time complexity O(log N).
  • Deletion: deleting the top element of the heap or the highest priority element, and then organizing the heap and returning the element with time complexity O(log N).
  • Peek: to check or find the most prior element in the heap, (max or min element for max and min heap).

Application of Heap Data Structure:

  • Heap is used to construct a priority queue.
  • Heap sort is one of the fastest sorting algorithms with time complexity of O(N* log(N), and it’s easy to implement.
  • Best First Search (BFS) is an informed search, where unlike the queue in Breadth-First Search, this technique is implemented using a priority queue.

Real-Time Application of Heap:

  • Patient treatment: In a hospital, an emergency patient, or the patient with more injury is treated first. Here the priority is the degree of injury.
  • Systems concerned with security use heap sort, like the Linux kernel.

Advantages of Heap Data Structure:

  • Less time complexity, for inserting or deleting an element in the heap the time complexity is just O(log N).
  • It helps to find the minimum number and greatest number.
  • To just peek at the most prior element the time complexity is constant O(1).
  • Can be implemented using an array, it doesn’t need any extra space for pointer.
  • A binary heap is a balanced binary tree, and easy to implement.
  • Heap can be created with O(N) time.

Disadvantages of Heap Data Structure:

  • The time complexity for searching an element in Heap is O(N).
  • To find a successor or predecessor of an element, the heap takes O(N) time, whereas BST takes only O(log N) time.
  • To print all elements of the heap in sorted order time complexity is O(N*log N), whereas, for BST, it takes only O(N) time.
  • Memory management is more complex in heap memory because it is used globally. Heap memory is divided into two parts-old generations and the young generation etc. at java garbage collection.
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!