_aditya's blog

By _aditya, history, 7 years ago, In English

Lets say we have a running stream of numbers. We have to insert each element to a sorted list, before inserting we have to find the position of element in list. The only way I know to do it efficiently is augmenting a AVL tree. And also there are policy based data structures. do you know some algorithm that can do this in logn?

  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
7 years ago, hide # |
← Rev. 3  
Vote: I like it 0 Vote: I do not like it

You can do it in $$$O(nlog n)$$$ by keeping a BIT that stores frequency of elements, if the elements are not too large.

»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think there is a O(n logn) method which is to use an unordered map to discretize. (may have large constant factor)

Then we use a fenwick tree to see how many elements are placed in front of a certain index.

But that's assuming that you can preprocess your stream of numbers