previous | start | next

Invariants for the Key floor(Key k) Algorithm

For a binary search tree define invariants t and candiate

 t: Node reference to subtree that contains floor or null if no there
    is no such subtree.
 candidate: Node not in t whose key is the largest key less than the key in t
            or null if there is no such Node in the tree.
   

How should we intialize t and candidate so that the both descriptions are correct initially?

Assuming both t and candidate are initialized correctly, as t and candidate are updated, we make sure the invariant relation is maintained.

In that case how do we compute floor(k)?



previous | start | next