next up previous
Next: Up: Previous:

Determine Rank of a Node

Rank(T,x) $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; return rank of node x
1
$\;\;\;\;\;$rank = size(left(x)) + 1
2
$\;\;\;\;\;$while x $\neq$ root(T)
3
$\;\;\;\;\;$ $\;\;\;\;\;$if x = right(parent(x))
4
$\;\;\;\;\;$ $\;\;\;\;\;$then rank = rank + size(left(parent(x))) + 1
5
$\;\;\;\;\;$ $\;\;\;\;\;$x = parent(x)
6
$\;\;\;\;\;$return rank



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


next up previous
Next: Up: Previous: