title: Find running median from a stream of integers
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1309263/rolling-median-algorithm-in-c">Rolling median algorithm in C</a>  </p>
  </blockquote>
  
  
  
  <blockquote>
    <p>Given that integers are read from a data stream. Find median of elements read so far in efficient way. </p>
  </blockquote>
  
  <p>Solution I have read: We can use a max heap on left side to represent elements that are less than the effective median, and a min heap on right side to represent elements that are greater than the effective median.</p>
  
  <p>After processing an incoming element, the number of elements in heaps differ at most by 1 element. When both heaps contain the same number of elements, we find the average of heap's root data as effective median. When the heaps are not balanced, we select the effective median from the root of heap containing more elements.</p>
  
  <p>But how would we construct a max heap and min heap i.e. how would we know the effective median here? I think that we would insert 1 element in max-heap and then the next 1 element in min-heap, and so on for all the elements. Correct me If I am wrong here.</p>