next up previous
Next: Up: Previous:

Analysis

Could write this code iteratively:

   if k < key(n)
   then n = left(n)
   else n = right(n)
   LOOP



   Min(n)     ; leftmost leaf of tree rooted at n
      while left(n) <> NIL
         n = left(n)
      return n
Min is O(h)



   Max(n)     ; rightmost leaf of tree rooted at n
      while right(n) <> NIL
         n = right(n)
      return n
Max is O(h)


next up previous
Next: Up: Previous: