DSA Lesson 29 of 33

Heap

Learn the heap data structure and priority-based processing.

Course Progress88%

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

  1. What is a heap?
  2. What is a min-heap?
  3. What is a max-heap?
  4. Where are heaps used?