A Heap is a complete binary tree where every parent is smaller (min-heap) or larger (max-heap) than its children. It's stored as an array.
Array-to-tree mapping (0-indexed):
Parent of i: Math.floor((i - 1) / 2)
Left child of i: 2 * i + 1
Right child of i: 2 * i + 2
Operations:
insert: add at end, bubble up — O(log n)
extractMin: remove root, bubble down — O(log n)
peek: return root — O(1)
Applications:
- Priority queues
- Heap Sort
- Dijkstra's algorithm
- Finding k-th smallest/largest
Related algorithms
Frequently asked questions
- What is Heap (Min Heap)?
- A Heap is a complete binary tree where every parent is smaller (min-heap) or larger (max-heap) than its children. It's stored as an array.
- What is the complexity of Heap (Min Heap)?
- Heap (Min Heap) is explained with a step-by-step visualization, including time and space complexity where applicable.
- Who is this Heap (Min Heap) visualizer for?
- The Heap (Min Heap) visualization targets intermediate-level learners in the Data Structures category. Useful for students, interview prep, and hands-on review.
- What algorithms are related to Heap (Min Heap)?
- In the same category (Data Structures) you can explore: Stack, Queue, Linked List. Each has an interactive visualization.