Data Structures19 sections · 729 units
Open in Course

Lessons from Median Stream

Two heaps pattern

What did you learn?

1.1. Two heaps can partition data around a median (or any percentile).

2.2. The insertion order (add to one, transfer, rebalance) ensures both invariants are maintained.

3.3. This pattern generalizes: use two heaps whenever you need efficient access to a "middle" element. Applications: sliding window median, stream percentiles, game matchmaking (median skill).