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 216685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:35:15+00:00 2026-05-11T18:35:15+00:00

I am looking for an idea, concept or proven datastructure that would be very

  • 0

I am looking for an idea, concept or proven datastructure that would be very efficient when accessing a collection that keeps cumulative values.

Example may shed more light on my need:

I have a list of values (2,3,5).
This list when looking at the cumulative values would be (2,5,10).

I will now add 1 at the start of the list and get (1,2,3,5) and in cumulative terms (1,3,6,11).

I only need to look at the cumulative values, I am not at all interested in the 1,2,3,5. I need to be able to quickly insert at position, remove a position and all this should quickly update the cumulative array (ideally without iterating throughout the whole array and recalculating the values.

Any ideas or hints ?

@Kristo (too long to put in the commentary): To clarify why negative numbers would make the total sum value meaningless please follow this example.

Insert 1 followed by -1. Sum is 1 than 0.
(1,-1) // (1,0)
Insert 3 followed by insert -3. Sum is 3 then 0.
(1,3,-1,-3) // (1,4,3,0)
Insert 2 followed by insert -2. Sum is 2 then 0.
(1,3,2,-1,-2,-3) // (1,4,6,5,3,0)

If my “magic number” were 4 total sum wouldn’t tell me whether I’ve exceeded it.

PS: The main reason for this is to be able to tell if I went over a certain value and where in the chain.

  • 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-11T18:35:15+00:00Added an answer on May 11, 2026 at 6:35 pm

    The only optimization I can think of is to do a ‘lazy’ evaluation of the cumulative list.

    in addition to your list of source values, keep track of a number of the highest position in the cumulative list that is accurate. if you need a number higher than that then you walk up the list, updating the values, and the index.

    idx  values       cumulative    operation
     3   (2,3,5)      (2, 5, 10)
     0   (1,2,3,5)    (X,X,X,X)     insert 1 at 0 
     3   (1,2,3,5)    (1,3,6,X)     look for value over 5     
     3   (1,2,3,5,4)  (1,3,6,X,X)   insert 4 at 4 
    

    if course, this wont do you a whole lot of good if you are usually adding items early in the list….

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

Sidebar

Related Questions

Looking for an example that: Launches an EXE Waits for the EXE to finish.
I have an application that is very connection-based, i.e. multiple inputs/outputs. The UI concept
I'm looking at the Database Project in VS2010, the idea being that I want
I'm looking into the idea of rolling out the web-based SSRS Report Builder to
I'm looking to create an Intellij IDEA language support plugin for Erlang. The first
I have a coworker who is looking to switch from InteilliJ Idea to Eclipse,
I'm looking to the equivalent of Windows _wfopen() under Mac OS X. Any idea?
Looking to do a very small, quick 'n dirty side project. I like the
Looking for a Linux application (or Firefox extension) that will allow me to scrape
The concept of a splash screen doesn't strike me as something that should be

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.