Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for an efficient algorithm to find streaming data median. Median is described as the numerical value separating the higher half of a sample, a population, or a probability distribution, from the lower half.

We have stream of data in our system like 1, 10, -40, 20, 2, 6,.....Our task is find median of data as they arrive.

share|cite|improve this question
Perhaps this would be of use:… I think "online" rather than "streaming" would be more efficient in searching for an answer to this. – Shaull Feb 15 '13 at 17:54
If you can store the stream of data as it comes in, the two-heap approach can be used. If you cannot store, I think you will only be able to find the approximate median. – Paresh Feb 15 '13 at 17:57
Further to the comment of Paresh, to find the exact median in the worst case requires storing half of the input numbers. The answers at SO discuss the solution using two heaps to keep track of the values below and above the median so far, which requires storing all the numbers. – András Salamon Apr 24 '13 at 9:12

You can find the median approximately with this: Approximate Medians and other Quantiles in One Pass and With Limited Memory, to some degree of confidence. That algorithm works, but it's pretty slow. One of the authors of that paper, Gurmeet Manku, has some other publications that might be what you're looking for, also.

There's a stackoverflow question that seems relevant.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.