I want you to give me a hint to prove this exercise from Cormen’s book: “Prove that no matter that the node starts with a binary search tree of height h, consecutive TREE-SUCCESSOR calls take O (k + h) time.
x
z
k
p
y
2h
O(h)
output
x.key
z.key
O(k)
O(h+k)
Hint: work out a small example, observe the result, try to extrapolate the reason.
, .
node, k Tree-Succcesor - . ( ) ? (: (x)). , (?).
: O(2h+k).
O(2h+k)