Skip to interview prep
Apexed

8. What is a heap and where is it used?

MediumData structures & algorithms

Technical
Show model answer

A binary heap is a complete tree stored in an array where each parent is ≤ (min-heap) or ≥ (max-heap) its children. Reading the top is O(1); insert and remove-top are O(log n).

Heaps implement priority queues: scheduling, Dijkstra's shortest path, merging k sorted lists, and keeping the top-k items from a stream.

What is a heap and where is it used — Software engineering interview question — Apexed