When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

ninjamayank's blog

By ninjamayank, history, 22 months ago, In English

Is there any way to find index of an element in a treeset in java?

  • Vote: I like it
  • -4
  • Vote: I do not like it

»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ninjamayank (previous revision, new revision, compare).

»
22 months ago, # |
  Vote: I like it -7 Vote: I do not like it

why not? iterate over all elements, maintain a counter. when you meet your desired element you return the value of the counter. The time complexity is linear in size of the treeset. but I'm guessing this is not what you're looking for.

Everything is possible — Barrack Schwarzenegger, 2025.

»
22 months ago, # |
  Vote: I like it -27 Vote: I do not like it

Just use C.

Marinush

»
22 months ago, # |
  Vote: I like it +7 Vote: I do not like it

with Treeset, there isn't besides doing linear, however you could implement our own binary tree and use binary search to localize the element. Another option would be use FendWick Tree

»
22 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Refer to this

»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

What problem caused you to need such a data structure though, I'm curious?