If you also support counting the number of left and right descendants of a node, you can do this in O (logN) by searching for the median position. In fact, you can find the kth largest element in O (logn) time.
Of course, this suggests that the tree is balanced. Keeping the count does not change the complexity of the insert / delete.
If the tree is not balanced, then you have the complexity of the worst case of Omega (n).
See: Order a statistical tree .
btw, BigO and Smallo are very different (your title says Smallo).
Aryabhatta
source share