For the following data structure:
we can use a balanced BST which each node has size of it's subtree, but it needs to implement red-black tree which is not fast to code.
any better solution?
The general type of structure you are looking for is qualified with Indexed or Indexable, that is a structure augmented with count to be able to access elements by indexes.
You could use either:
(and perhaps a few others :p)
I tend to think that Skip-Lists are easier to implement than BST, as you can use a randomized height instead of all the balancing stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With