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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 152k
  • Answers 152k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Doesn't the codecvt template take the state type as a… May 12, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer Yes, you can do this. See the MySQL reference (version… May 12, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer When sending a length field on a TCP stream, you… May 12, 2026 at 10:06 am

Related Questions

I want to create something similiar to a facebook wall on my social site.
This is a XAML code sample taken from the MSDN library article for the
I'm just starting to read TAOCP Volume 1 and I'm having trouble understanding the
I am looking for an app that will let me type in code ON

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.