Glossary

Heap & Priority Queue — definition.

Definition

A data structure that returns the min or max in O(log n) per operation.

Complexity

Insert/pop O(log n); peek O(1); heapify O(n).

When to use it

  • Top-K or k-th largest queries.
  • Merge-K sorted streams.
  • Scheduling the earliest-available resource.

Representative scenarios

  • Leaderboard Live-Rank — top-k scores as events stream.
  • Barista Rotation — next free barista among k.
  • Multi-Feed Merger — k-way merge of sorted feeds.

Related patterns

Read the full pattern page: Heap & Priority Queue — template, code, and drills.

Run the free diagnostic.

Ten-minute patterns quiz. No card. Personalized loop starts on the other side.