Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 418313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:39:59+00:00 2026-05-12T18:39:59+00:00

Update Just for future reference, I’m going to list all of the statistics that

  • 0

Update

Just for future reference, I’m going to list all of the statistics that I’m aware of that can be maintained in a rolling collection, recalculated as an O(1) operation on every addition/removal (this is really how I should’ve worded the question from the beginning):

Obvious

  • Count
  • Sum
  • Mean
  • Max*
  • Min*
  • Median**

Less Obvious

  • Variance
  • Standard Deviation
  • Skewness
  • Kurtosis
  • Mode***
  • Weighted Average
  • Weighted Moving Average****

OK, so to put it more accurately: these are not “all” of the statistics I’m aware of. They’re just the ones that I can remember off the top of my head right now.

*Can be recalculated in O(1) for additions only, or for additions and removals if the collection is sorted (but in this case, insertion is not O(1)). Removals potentially incur an O(n) recalculation for non-sorted collections.

**Recalculated in O(1) for a sorted, indexed collection only.

***Requires a fairly complex data structure to recalculate in O(1).

****This can certainly be achieved in O(1) for additions and removals when the weights are assigned in a linearly descending fashion. In other scenarios, I’m not sure.


Original Question

Say I maintain a collection of numerical data — let’s say, just a bunch of numbers. For this data, there are loads of calculated values that might be of interest; one example would be the sum. To get the sum of all this data, I could…

Option 1: Iterate through the collection, adding all the values:

double sum = 0.0;
for (int i = 0; i < values.Count; i++) sum += values[i];

Option 2: Maintain the sum, eliminating the need to ever iterate over the collection just to find the sum:

void Add(double value) {
    values.Add(value);
    sum += value;
}

void Remove(double value) {
    values.Remove(value);
    sum -= value;
}

EDIT: To put this question in more relatable terms, let’s compare the two options above to a (sort of) real-world situation:

Suppose I start listing numbers out loud and ask you to keep them in your head. I start by saying, “11, 16, 13, 12.” If you’ve just been remembering the numbers themselves and nothing more, and then I say, “What’s the sum?”, you’d have to think to yourself, “OK, what’s 11 + 16 + 13 + 12?” before responding, “52.” If, on the other hand, you had been keeping track of the sum yourself while I was listing the numbers (i.e., when I said, “11” you thought “11”, when I said “16”, you thought, “27,” and so on), you could answer “52” right away. Then if I say, “OK, now forget the number 16,” if you’ve been keeping track of the sum inside your head you can simply take 16 away from 52 and know that the new sum is 36, rather than taking 16 off the list and them summing up 11 + 13 + 12.

So my question is, what other calculations, other than the obvious ones like sum and average, are like this?


SECOND EDIT: As an arbitrary example of a statistic that (I’m almost certain) does require iteration — and therefore cannot be maintained as simply as a sum or average — consider if I asked you, “how many numbers in this collection are divisible by the min?” Let’s say the numbers are 5, 15, 19, 20, 21, 25, and 30. The min of this set is 5, which divides into 5, 15, 20, 25, and 30 (but not 19 or 21), so the answer is 5. Now if I remove 5 from the collection and ask the same question, the answer is now 2, since only 15 and 30 are divisible by the new min of 15; but, as far as I can tell, you cannot know this without going through the collection again.

So I think this gets to the heart of my question: if we can divide kinds of statistics into these categories, those that are maintainable (my own term, maybe there’s a more official one somewhere) versus those that require iteration to compute any time a collection is changed, what are all the maintainable ones?

What I am asking about is not strictly the same as an online algorithm (though I sincerely thank those of you who introduced me to that concept). An online algorithm can begin its work without having even seen all of the input data; the maintainable statistics I am seeking will certainly have seen all the data, they just don’t need to reiterate through it over and over again whenever it changes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:39:59+00:00Added an answer on May 12, 2026 at 6:39 pm

    First, the term that you want here is online algorithm. All moments (mean, standard deviation, skew, etc.) can be calculated online. Others include the minimum and maximum. Note that median and mode can not be calculated online.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: So pretty much everyone here has told me that I just need to
I just installed Eclipse Galileo for Java developers and noticed that the update site
Update: Last night, I decided that this is just too much work to change
I just pulled https://github.com/kolanos/kohana-universe and now I'm trying to update all the modules running:
I'm trying to rebuild zlib.net and create an assembly I can reference in future
Update: I just tested my JSON format returned from the server using JSONlint and
I have developed a windows forms c# application, i just want update items in
I just did an update of my SDK and now eclipse is giving me
I just used Android SDK Manager to update Android SDK Tools to revision 17,
I was just reading an update from a friend's project, mentioning the use of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.