### Jass_Manak's blog

By Jass_Manak, history, 2 years ago,

What can be used in Java in place of ordered_set in C++?

• +27

 » 2 years ago, # |   +95 C++ can be used in place of Java
•  » » 2 years ago, # ^ |   +13 Are u sure it will work?
 » 2 years ago, # |   0 How about TreeSet?
•  » » 2 years ago, # ^ |   0 I have to find the Kth largest elememt. Is there any way to find it using TreeSet?
•  » » » 2 years ago, # ^ |   0 Not really. But you can use O(N) algorithm described in https://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array-set-2-expected-linear-time/, or use a handwritten binary search tree that for each node keeps the total number of nodes in the corresponding subtree.
•  » » » » 2 years ago, # ^ |   0 Ohk. Thanks
•  » » » 2 years ago, # ^ | ← Rev. 2 →   0 I have to find the Kth largest elememt. Is there any way to find it using TreeSet?No efficient way for doing this with stock Java TreeSet / TreeMap. And you made me curious whether there is a way of doing it in C++? I cannot find anything useful based on this API: http://www.cplusplus.com/reference/set/set/UPDATE: found it, now I see the advantage over Java: https://www.geeksforgeeks.org/ordered-set-gnu-c-pbds/
•  » » » » 2 years ago, # ^ |   0 Yup
•  » » » » » 2 years ago, # ^ |   0 Jass_Manak maybe you have some concrete problems where this feature is useful?
•  » » » » » » 2 years ago, # ^ |   +8 Yeah, I have to use that in some problem from the ongoing contest. So, can't tell the exact problem right now.
 » 2 years ago, # | ← Rev. 2 →   0 In applications where memory is not a constraint, you can use Fenwick Tree. Although this is not available in the Java API, it is very easy to code this DS (doable in 5 min). I think even under tight memory constraints, some geniuses in the CP community have ways to make this DS "lazy" in order to save memory.