Theory
A heap is a specialized tree-based data structure that satisfies the heap property. In a min-heap, the smallest element is at the root. In a max-heap, the largest element is at the root. Heaps are commonly used to implement priority queues.
Example
const minHeap = [1, 3, 5, 7, 9];
console.log("Smallest:", minHeap[0]);
Expected Output
Smallest: 1
Practice
Study how insertion and deletion work in a min-heap.
Interview Questions
- What is a heap?
- What is a min-heap?
- What is a max-heap?
- Where are heaps used?