LearnThatStack Ace your next interview
Trees, BSTs & Heaps · question
Question 11 of 76

What is the difference between a min-heap and a max-heap?

beginner
← All Trees, BSTs & Heaps questions
Re-explain

The only difference is which extreme sits at the root. A min-heap keeps its smallest value on top, and a max-heap keeps its largest. Both obey the same shape rule and the same parent-child ordering, just flipped.

In a min-heap, every parent is smaller than or equal to its children. In a max-heap, every parent is larger than or equal to its children. Neither orders siblings, so you cannot read a sorted list off the array.

You pick based on what you pull first. To take the cheapest task next, use a min-heap. To take the highest-scoring item, use a max-heap. Peeking at the top costs O(1), and removing it costs O(log n) either way.

If your library only ships one kind, negating numeric keys fakes the other.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Trees, BSTs & Heaps One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

What you can say

  1. The only difference is which extreme sits at the root. A min-heap keeps the smallest value on top, and a max-heap keeps the largest.
  2. Both have the same shape and the same parent-child rule, just flipped. In a min-heap every parent is smaller than or equal to its children, and in a max-heap it is larger or equal.
  3. Neither one orders siblings, so the array is not sorted. The top is the only position you can be sure about.
  4. I pick based on what I need to pull first. If I want the cheapest task next, I use a min-heap. If I want the highest score, I use a max-heap.
  5. The costs are the same either way. Peeking at the top is O(1), and removing it is O(log n).
  6. A heap only answers for one end, so if the library ships just one kind, I negate numeric keys to fake the other. That trick works for numbers, not for strings.

Weak answers to avoid

  • Says a min-heap is sorted in ascending order Only parents and children are ordered, never siblings, so the array is not sorted. Say the root is the one position whose value you know for sure.
  • Describes a heap like a BST, smaller on the left A heap has no left-right rule. The order runs from parent to child only, so reading the top is O(1) but finding any other value takes a scan.
  • Treats them as two different structures Same shape, same sift-up and sift-down, same costs. Only the comparison flips. Peek is O(1) and removing the top is O(log n) in both.
  • Defines both but never says when to use which Tie the choice to what you pull first. Taking the cheapest task next calls for a min-heap, and taking the highest score next calls for a max-heap.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Trees, BSTs & Heaps cheatsheet.

← Back to all Trees, BSTs & Heaps questions
Pro · $10/mo

65 of 76 Trees, BSTs & Heaps answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime