Блог пользователя _aditya

Автор _aditya, история, 5 лет назад, По-английски

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?

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
5 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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