Data Structures & Algorithms
Min Heap
Trees and HeapsA Min-Heap is a type of binary tree where the smallest value is always at the top (the root), and each parent node is always smaller than or equal to its child nodes.
There are some important rules that define a Min-Heap:
The tree must be a complete binary tree. This means all levels of the tree are filled except maybe the last, and nodes are filled from left to right.
Every parent node must be less than or equal to its children.
The smallest value is always at the root.
Here’s a quick example:
2
/ \
5 3
/ \ \
9 6 8How is a Min-Heap Different from a Binary Search Tree?
A Min-Heap is not the same as a BST. Here are the key differences:
1. Ordering:
In a BST, the left child must be less than the parent, and the right child must be greater than the parent.
In a Min-Heap, the only rule is that the parent is smaller than the children — it doesn’t matter whether the child is on the left or right.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 42 more lessons in Data Structures & Algorithms.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.