next up previous
Next: Up: Previous:

Solution:

Use Augmented Red-Black Trees.

Define an order statistic tree as a Red-Black tree with an added size(x) field that contains the number of internal nodes in the subtree rooted at node x, where

size(x) = \(\left\{ \begin{array}{ll}
0 & {\rm if} \; x=NIL \\
1 \;+\; size(left(x)) \;+\; size(right(x)) & {\rm otherwise}
\end{array} \right.\)


next up previous
Next: Up: Previous: