# Streaming algorithms for sum

First of all, I am not sure whether this is a research level question. Please let me know if it is not.

The question is about streaming algorithms for the sum of the given data stream. From literature, it is common to consider the questions related to the frequency vector, say, $\vec{m}$, and one has standard algorithms to approximate the p-norm of such a vector. However, a very natural question is, is it possible to approximate the sum of the stream. More formally, suppose we have a frequency vector $\vec{m}$ for the "value vector" $\vec{a}$, i.e., each $a_i$ appears $m_i$ times in the stream, the sum is $\sum a_i\cdot m_i$. (Of course, we assume each $a_i$ is within some interval $I$, as otherwise the question might not be very interesting.)

I noticed that Braverman has papers regarding approximate $\sum_i G(m_i)$ for reasonably general function $G$, but here, with different index $i$, $G$ varies. Hence it is not clear to me how to apply.

• Say $a_i \in [m]$ and $i \in [n]$. You can trivially just keep a single sum variable and add to it each $a_i$ as it appears, for an $O(\log(m + \log n)$ bit exact solution, which is easily seen to be optimal. Morris's approximate counting algorithm gives a constant factor approximation to the sum in $O(\log \log m + \log \log n)$ bits: algo.inria.fr/flajolet/Publications/Flajolet85c.pdf – Sasho Nikolov Apr 27 '16 at 20:06