I need to implement two rank queries [rank(k)
and select(r)
]. But before I can start on this, I need to figure out how the two functions work.
As far as I know, rank(k)
returns the rank of a given key k
, and select(r)
returns the key of a given rank r
.
So my questions are:
1.) How do you calculate the rank of a node in an AVL(self balancing BST)?
2.) Is it possible for more than one key to have the same rank? And if so, what woulud select(r)
return?
I'm going to include a sample AVL tree which you can refer to if it helps answer the question.
Thanks!