Insertion into a sorted list in constant time

I have a sorted list of integers, and I want to insert any element into this list in constant time. I am allowed to do preprocessing if it allows me to start this operation in constant time (i.e. no matter how many times I repeat this operation after preprocessing, it should work in constant time).

How can I do that?

Edit: I can come up with a couple more limitations to make it a little less ambiguous and a little harder to solve -

  • the list should be stored in sorted order after insertion (s)
  • Or, the list must somehow support the maximum / minimum operations in the post-processing (s) of the time.
+4
source share
3 answers

You can put integers in the base tree by treating integers as bit strings. With a radius of 2 and a list of 32-bit integers, you will have a maximum tree depth of 32, which is your constant factor for pasting in constant time (you would usually not do something like this because the constant coefficient for the radix tree is probably will be more than the log factor of a balanced binary tree, plus all the bit-bits that you will need to do for the radix tree will be expensive)

+5
source

Use LinkedHashMap. Decide how many items are stored on the hash code (say, integers 0-10 are hash (1), integers 11-20 are hash (2), etc.)

, O (1) → - ( O (1)) → insert O (1). , .

+2

A y fast trie O (log (log (M)) //, M - . - O (n).

http://en.wikipedia.org/wiki/Y-fast_trie

0

All Articles