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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:15:17+00:00 2026-06-12T23:15:17+00:00

I have a large (> million elements) tree, and each element has an ‘offset’

  • 0

I have a large (> million elements) tree, and each element has an ‘offset’ field that refers to something external. I need to do both:

  1. Insert new elements at arbitrary positions. Each insertion will cause the ‘offset’ field of later elements to be increased by some amount.
  2. Quickly obtain the offset value of an element.

If 2 wasn’t a requirement, I’d store offsets relative to the previous one, then there’d be no need to update everything after an insertion. But that would mean I’d need to add up every previous offset to calculate one element’s absolute value.

Is there a canonical way of doing this sort of thing? I was thinking maybe a compromise, where eg every nth element would have an absolute offset, and the other elements’ offsets would be relative to the previous absolute one, meaning I’d have to do a small amount of traversal in both cases.

  • 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-06-12T23:15:18+00:00Added an answer on June 12, 2026 at 11:15 pm

    There a few approaches that are somewhat based on your idea of having some elements store an absolute offset.

    One of them (I think it’s a version of tiered vector) is to store the change in offset for the first consecutive sqrt(N) elements, then for the elements from sqrt(N) to 2 * sqrt(N) and so on. Then, in order to find the offset for a given element, you need to sum all the consecutive sums of previous elements (which are at most sqrt(N) + 1, since (sqrt(N) ^ 2) = N) and then add the elements that are after the last whole group, but before the element you’re interested in. This gives you an O(sqrt(N)) insert and lookup time.

    You can also take this approach to the next level, and store the sums for:

    • the whole interval
    • the first and second half of the interval
    • the 1st…4th quarter, etc.

    This way, you get a data structure that is similar to an interval or segment tree, but not exactly the same. It can be implemented as a complete binary tree using a simple array. It gives you a complexity of O(log N) for both operations.

    A few improvements to this idea lead to Binary Indexed Trees, which have the same complexity, but use about half the space.

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

Sidebar

Related Questions

I have a relatively large database tables (just under a million rows) that has
I have a large disk file (around 8 GB) containing several million records that
Say if I have a large dataset, the table has well over a million
I have a very large numpy array (containing up to a million elements) like
I have a large number of phrases (~ several million), each less than six
I have a large table (~2 million rows), each row of which represents one
I have really large file with approximately 15 million entries. Each line in the
I have a large dataset (around 1.9 million rows) of 3D points that I'm
I have a very large (about 91 million non-zero entries) sparseMatrix() in R that
I have large data in two files each with about two million (different) entries.

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.