I have an idea of what I want the algorithm to do, but I’m looking to see if this has been implemented for me in python and I need to know the algorithm’s name.
I want to insert a set of values in the range [0,65535] into the container. I want to then ask the container for an arbitrary order statistic. Both insert and query should be logarithmic.
The standard way to do this is by using an augmented binary search tree. Essentially, in addition to keeping the set of keys stored in the tree, you keep a count of the nodes stored in each subtree. This lets you computer order statistics efficiently.
Since you’re dealing with bounded integers, you can just keep a binary search tree with the 65536 values stored in it, and keep a count of the number of elements stored in each subtree. This yields a running time of O(lg 65536) instead of O(lg n).