next up previous
Next: Up: Previous:

Pseudocode

Select(x,i) $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; return ith smallest key in subtree x
1
$\;\;\;\;\;$rank = size(left(x)) + 1
2
$\;\;\;\;\;$if i = rank
3
$\;\;\;\;\;$then return x
4
$\;\;\;\;\;$else if (i < rank)
5
$\;\;\;\;\;$ $\;\;\;\;\;$then return Select(left(x), i)
6
$\;\;\;\;\;$ $\;\;\;\;\;$else return Select(right(x), i - rank)



T(n) is approximately equal to height of tree = O(lg n)



\psfig{figure=figures/f6-28.ps}


next up previous
Next: Up: Previous: