Back to Home

Heaps

Heaps maintain quick access to the minimum or maximum element.

Key Ideas

  • Use a min-heap for smallest-first retrieval and a max-heap for largest-first.
  • Great for top-k, k-way merge, and streaming medians.
  • Many problems use a heap plus a hash map for lazy deletion.