top k selection
ranking frequency
max heap simulation
greedy selection
two heaps
merge k sorted structures
graph + heap
sliding window + heap
sorting + heap
interval + heap
1. Size-K Heap
- Keep only k elements → O(n log k)
3. Heap + Map Combo
5. Heap + Greedy
- always take best next option
2. Min vs Max Heap
- Python = min heap
- simulate max with negatives
4. Two Heaps
- balance halves for median
use heap when you see:
- You need repeated access to the best element
- You cannot afford full sorting
- You are processing dynamic or streaming data
- “top k” / “kth largest”
- “most frequent”
- “smallest/largest repeatedly”
- “stream of data”
- “merge sorted lists”