Median of Data Stream Using Two Heaps
📖 Scenario: Imagine you are building a system that receives numbers one by one, like scores from a game played live. You want to find the middle score (median) at any time quickly.
🎯 Goal: Build a program that keeps track of the median of numbers as they come in, using two heaps (priority queues) to organize the data efficiently.
📋 What You'll Learn
Use two heaps: a max-heap for the lower half of numbers and a min-heap for the upper half.
Balance the heaps so their sizes differ by at most one.
Insert numbers one by one and update the median after each insertion.
Print the median after all insertions.
💡 Why This Matters
🌍 Real World
Finding the median in real-time data streams like live sensor data, stock prices, or game scores.
💼 Career
Useful for roles in data engineering, real-time analytics, and software development involving streaming data.
Progress0 / 4 steps