Heap Data Structure
Last Updated :
04 Mar, 2025
Improve
A Heap is a complete binary tree data structure that satisfies the heap property: for every node, the value of its children is greater than or equal to its own value. Heaps are usually used to implement priority queues, where the smallest (or largest) element is always at the root of the tree.
Basics
Library Implementations
- Heap in C++ STL
- priority_queue in C++
- PriorityQueue in Java
- PriorityQueue in C#
- heapq in Python
- Heap in JavaScript
Easy Problems
- Check if an array is Heap?
- K’th Smallest & K'th Largest
- Heap Sort
- Heap Sort for Decreasing Order
- Height of a Heap with N Nodes
Medium Problems
- Nearly Sorted Array
- K Largest Elements & K Smallest
- k Closest Elements
- Check if Binary Tree is Heap
- Huffman Coding
- Nodes less than a value in a Min Heap.
- Connect n ropes with minimum cost
- Maximum distincts after removing k elements
- K maximum sum combinations from two arrays
- Median in a stream
- K’th largest in a stream
- Largest triplet product in a stream
- k most frequent
- Sort by Frequency
- Min Heap to Max Heap
- Check for Min-Heap from Level Order
Hard Problems
- K-th Largest Sum Subarray
- Find K Closest Points to the Origin
- Merge k sorted arrays
- Merge K Sorted Linked Lists
- Prim's Minimum Spanning Tree
- Dijkstra's Shortest Path
- Sort numbers stored on different machines
- Smallest Derangement of Sequence
- Largest Derangement of a Sequence
- Convert BST to Min Heap
- Merge two binary Max Heaps
- Minimum product of k integers
- Leaf starting point in a Binary Heap
- Rearrange characters such that no two same adjacent
- Sum of all between k1’th and k2’th smallest
- Min sum of two formed from given digits
- A data structure with min and max
Other Types of Heaps
Quick Links:
Recommended:


