I have a red-black tree (binary tree, all the leaves are within 2 levels).
I can navigate through nodes: to left, right or parent.
I know the entire count of nodes.
I have to find the N-th smallest element in a tree. Is there any way to do this faster than in O(n)? Any ideas of optimizing access by index?
In each node X you should store, how many nodes are in subtree with X as a root.
During each insert/delete you should use this equation to update counts in nodes affected by rotations.
After that solution is simple