The classic two-heap approach came to mind immediately but they pushed back on memory usage pretty fast.
Start by clarifying the constraints: what does 'limited memory' mean (e.g., fixed-size buffer, streaming data, no disk)? Then discuss approximate algorithms like the P² quantile estimator or reservoir sampling, and compare trade-offs between accuracy, memory, and update speed. Finally, propose a concrete implementation using a bounded data structure (e.g., two heaps with eviction) and explain how to handle the running median.
Pro tip: Mention that exact running median with limited memory is impossible for arbitrary data, so you must choose an approximation; showing awareness of this fundamental limit and then offering a practical solution demonstrates depth.
Ask about the data stream characteristics (size, distribution, order), memory limit (e.g., O(1), O(log n), fixed KB), and accuracy requirements (exact vs. approximate).
Explain that maintaining two heaps (max-heap for lower half, min-heap for upper half) gives O(n) memory, which may be too large; note that exact median requires storing all data in worst case.
Introduce streaming quantile estimators like P² (for a single quantile) or t-digest, which use O(1) or O(log n) memory and provide bounded error; mention reservoir sampling as a baseline.
Weigh memory usage, accuracy, update time, and implementation complexity; for example, P² uses constant memory and O(1) update, but may drift for non-stationary data.
Describe how to maintain the estimator: initialize with first few points, update markers based on incoming values, and periodically adjust to maintain quantile estimates.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.