Red-black tree access by ordinal index
问题 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? 回答1: In each node X you should store, how many nodes are in subtree with X as a root. count(LEAF) = 1 count(NODE) = count(NODE->LEFT) + count(NODE->RIGHT) + 1 During each insert/delete you