What is a binary heap, and how do min-heap and max-heap differ?
PICTURE THIS: ARRAY IN MEMORY
Index starts at 0. Scan once for max — O(n).
Simple meaning
A binary heap is a complete binary tree stored in an array with parent-child index math.
WHY — Heap instead of guessing?
Why interviewers care about Heap:
who only read docs from people who shipped.
and tied to DSA work.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1A binary heap is
a complete binary tree stored in an array with parent-child index math.
- 2A min-heap keeps the
smallest at the root
- 3How it works
a max-heap keeps the largest.
- 4Peek is O(1), insert
and delete-root are O(log n) via sift-up or sift-down.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
A binary heap is a complete binary tree stored in an array with parent-child index math. A min-heap keeps the smallest at the root