Concept Flow - Median of Data Stream Using Two Heaps
Start
New number arrives
Compare with max-heap root
Insert into max-heap
Insert into min-heap
Balance heaps sizes
Calculate median
Output median
Wait for next number
New numbers go into one of two heaps (max-heap for smaller half, min-heap for larger half). Heaps are balanced to keep sizes close. Median is from roots of heaps.
