Pattern 9: Heap / top-K
Comes up in: DSA
This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.
What it covers
- size-k heap for top-K (O(n log k))
- two heaps for running median
- scheduling with heaps
- quickselect alternative
Words you will know
What you will practise
- kth-largest (M)
- k-closest-points (M)
- top-k-frequent-words (M)
- task-scheduler (M)
- find-median-stream (H)
Interview questions this answers
- Find the k largest elements. Heap vs sorting vs quickselect?
- Keep a running median of a stream.