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 -
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)
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). , .
A y fast trie O (log (log (M)) //, M - . - O (n).
http://en.wikipedia.org/wiki/Y-fast_trie