This question has been around for while, but I still have a question please. I will discuss the following solution.
Question: Prove that no matter what node we start at in a height-h binary search tree, k successive calls to TREE-SUCCESSOR take O(k + h) time.
Given tree successor algorithm below, that given an x, it will find it's left-most node of right-subtree of x:
Assumptions: Assuming that the worst-case running time of TREE-SUCCESSOR() is O(h), where h is the height of binary search tree and the tree will not be changed between successive calls of the method. The worst case happens when next successor is a leaf at depth h.
You need to call once the method to get the next successor and you need O(h) time for that. Once when you have the next successor you simply can store it and for every other call, you can return it in O(1). Since, you have k−1 remaining calls, the running time is O(k). Combining with the above, you have that the total running time is O(h)+O(k)=O(k+h).
Question: I am not sure by the last statement about how we got running time O(k) please? I assume k successive calls to TREE-SUCCESSOR() means that we are calling it k times on probably same or different nodes? If that is the case, we know that worst time for TREE-SUCCESSOR is O(h), so how we got a total time of O(h+k) please? I can see that if we call TREE-SUCCESSOR() k times, then we should get worst-case of O(kh).
Edit: I would assume probably that k succissive calls to TREE-SUCCESSOR() means: TREE-SUCCESSOR()+⋯+TREE-SUCCESSOR(): k times?
