Tuesday, March 6, 2012

Given a stream of integers compute the average in every instant

2 comments:

  1. like http://search.cpan.org/~nids/Statistics-OnLine-0.02/lib/Statistics/OnLine.pm ?

    ReplyDelete
  2. Online algorithm.

    sum = 0;
    count = 0;
    avg = 0;
    while( stream not empty )
    {
    sum += next integer;
    count += 1;

    avg = sum/count;
    }

    Anything that I am missing? :)

    ReplyDelete