Data Structures19 sections · 729 units
Open in Course

When to Use Heaps

Pattern signals

Look for these signals:

1.1. "K-th largest/smallest": bounded heap of size kk

2.2. "Top K elements": heap selection

3.3. "Merge sorted sequences": k-way merge

4.4. "Running median or percentile": two heaps

5.5. "Process by priority": simulation with priority queue

6.6. "Repeatedly need min/max": basic heap If you're repeatedly extracting extrema, a heap is likely the answer.