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

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

Is there any way to get index of an element in TreeSet?

I want a data structure(like set in c++) which can handle deletions in O(1) and do search(like lower_bound in c++) in O(logn) time.

Is there any inbuilt data structure in Java which supports the above operations?

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

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

Lol. How do you even maintain an ordering of elements with O(1) deletion time? Unless you tell me that you are only deleting the largest/smallest element at any one time.

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

    C++ has std:set which is a sorted container and performs erase(int position) in O(1). I just asked if there is a equivalent data structure of Set in Java which supports those operations. What's there to laugh in that ?

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +7 Проголосовать: не нравится

      std::set erases by iterator in o(1), KeyIterator.remove also works in amortized constant.

      I do not know of standard library navigable set with quick access by index