# Calculating average without knowing number of elements

I would like to calculate the average of a a set of numbers without knowing the sum of the set. In other words, I want to calculate the average with knowing as little information as possible.

Note: I do not want to use $\frac{sum}{total}$

I am using looping (induction, I believe) to calculate the average.

I would like to keep track of only one variable, say x, which is equal to the current accuracy.

Is it possible to calculate x without knowing sum?

In summary: seeking how can you calculate the new average knowing only the number of elements and the current average.

Notice that sum is the current average times the current number of elements...

Suppose that $a(n)$ is the average of the first $n$ elements of the set and $e$ is the $n+1^{\text{st}}$ element. Then $$a(n+1) = \frac{n a(n) + e}{n+1} \text{.}$$ Of course, all this does is reconstruct sum, update it with the new element and then divide to get the new running average.

You need to keep track of two numbers. If you don't you don't know how much a new number changes the average. Say the average of the first bunch is $100$ and you get a new one of $1$. If the first bunch is just one, the new average is $50.5$. If the first batch is $100$ the new average is about $99$.

You can do it in a loop if you keep track of the current average $a$ and the number of items seen so far $n$. This hides the fact that the total so far is $an$. If you get a new value $d$ you can update the average to be $\frac {an+d}{n+1}$ and the count to be $n+1$. In a sense this is doing the same thing, but you don't have to keep the whole list available.

Find the average of $$\{ 3,5,6,2\}$$
$$3+5=8,8/2 = 4$$
$$2(4)+6 =14, 14/3 = 14/3$$
$$3(14/3)+2=16, 16/4=4$$