17 worked problems

Heaps

Priority queues — always grab the smallest or largest fast. You repeatedly need the smallest or largest active candidate while the candidate set changes.

Recognition signal

When should you think of Heaps?

You repeatedly need the smallest or largest active candidate while the candidate set changes.

Core invariant

What must stay true?

The heap root is always the next globally valid choice among inserted candidates.

Practice in a deliberate order

What to learn in this cluster

  1. 01Top-k selection
  2. 02Merging sorted sources
  3. 03Scheduling, streaming, and shortest paths

All Heaps problems

17 of 17 walkthroughs
Continue the cluster

Related patterns and study guides