Practice Discrete Math

Algorithms / Heap Sort Selection Tradeoffs

Least You Need to Know: Heap vs Sort vs Selection Tradeoffs

Interview problems often hide the real choice behind words like top-k, streaming, repeated extraction, or one-shot kth element. Heaps, full sorting, and selection algorithms all solve related ranking problems, but they optimize different requirements: repeated updates, complete ordering, or a single target rank.

The least you need to know

Key notation

heap priority-queue structure supporting fast access to the smallest or largest key
streaming top-k maintain the current best `k` items while data arrives
one-shot selection solve for a single rank once

Tiny worked example

  • If you need the next smallest item many times, a heap supports repeated extraction naturally.
  • If you only need the kth smallest once, quickselect-style selection avoids sorting everything.
  • If you need the final full order for output or downstream logic, sorting is the clearest target.

Common mistakes

How to recognize this kind of problem

Start practice