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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:14:15+00:00 2026-05-27T12:14:15+00:00

I’m looking for an ordered data structure which allows very fast insertion. That’s the

  • 0

I’m looking for an ordered data structure which allows very fast insertion. That’s the only property required. Data will only be accessed and deleted from the top element.

To be more precised, i need 2 structures :

1) The first structure should allow an ordered insertion using an int value. On completing the insertion, it shall report the rank of the inserted element.

2) The second structure should allow insertion at a specified rank.

The number of elements to be stored is likely to be in thousands, or tens of thousands.

[edit] i must amend the volume hypothesis : even though, at any moment, the size of the ordered structure is likely to be in the range of tens of thousands, the total number of insertion is likely to be in the tens of millions per run.

Insertion time in O(1) would be nice, although O(log(log(n))) is very acceptable too. Currently i’ve got some interesting candidate for First structure only, but either in log(n), or without the capability to report insertion rank (which is mandatory).

  • 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-27T12:14:15+00:00Added an answer on May 27, 2026 at 12:14 pm

    What about a form of skip-list, specifically the ” indexed skiplist” in the linked article. That should give O(lg N) insert and lookup, and O(1) access to the first node for both your use cases.

    –Edit–

    When I think of O(1) algorithms, I think of radix-based methods. Here is an O(1) insert with rank returned. The idea is to break the key up into nibbles, and keep count of all the inserted items which have that prefix. Unfortunately, the the constant is high (<=64 dereferences and additions), and the storage is O(2 x 2^INT_BITS), which is awful. This is the version for 16 bit ints, expanding to 32 bits should be straightforward.

    int *p1;int *p2;int *p3;int *p4;
    void **records;
    unsigned int min = 0xFFFF;
    
    int init(void)     {
       p1 = (int*)calloc(16,sizeof(int));
       p2 = (int*)calloc(256, sizeof(int));
       p3 = (int*)calloc(4096, sizeof(int));
       p4 = (int*)calloc(65536,sizeof(int));
       records = (void**)calloc(65536,sizeof(void*));
       return 0;
    }
    
    //records that we are storing one more item, 
    //counts the number of smaller existing items
    int Add1ReturnRank(int* p, int offset, int a) {
       int i, sum=0;
       p+=offset;
       for (i=0;i<a;i++)
          sum += p[i];
       p[i]++;
       return sum;
    }
    
    int insert(int key, void* data) {
       unsigned int i4 = (unsigned int)key;
       unsigned int i3= (i4>> 4);
       unsigned int i2= (i3>> 4);
       unsigned int i1= (i2>> 4);
       int rank = Add1ReturnRank(p1,0, i1&0xF);
       rank += Add1ReturnRank(p2,i2&0xF0,i2&0xF);
       rank += Add1ReturnRank(p3,i3&0xFF0,i3&0xF);
       rank += Add1ReturnRank(p4,i4&0xFFF0,i4&0xF);
       if (min>key) {min = key;}
       store(&records[i4],data);
       return rank;
    }
    

    This structure also supports O(1) GetMin and RemoveMin. (GetMin is instant, Remove has a constant similar to Insert.)

    void* getMin(int* key) {
        return data[*key=min];
    }
    
    void* removeMin(int* key)  {
       int next = 0;
       void* data = records[min];
       unsigned int i4 = min;
       unsigned int i3= (i4>> 4);
       unsigned int i2= (i3>> 4);
       unsigned int i1= (i2>> 4);
    
       p4[i4]--;
       p3[i3]--;
       p2[i2]--;
       p1[i1]--;
       *key = min;
       while (!p1[i1]) {
          if (i1==15) { min = 0xFFFF; return NULL;}
          i2 = (++i1)<<4;
       }
       while (!p2[i2])
          i3 = (++i2)<<4;
       while (!p3[i3])
          i4 = (++i3)<<4;
       while (!p4[i4])
          ++i4;
       min = i4;
       return data;
    }
    

    If your data is sparse and well distributed, you could remove the p4 counter, and instead do an insertion sort into the P3 level. That would reduce storage costs by 16, at the cost of a higher worst case insert when there are many similar values.

    Another idea to improve the storage would be to do combine this idea with something like an Extendable Hash. Use the integer key as the hash value, and keep count of the inserted nodes in the directory. Doing a sum over the relevant dictionary entries on an insert (as above) should still be O(1) with a large constant, but the storage would reduce to O(N)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.