Prove the efficiency of repeated calls to successor() in binary trees?

后端 未结 2 1156
粉色の甜心
粉色の甜心 2021-02-06 09:34

I need a hint for this exercise from the CLRS Algorithms book:

Prove that no matter what node we start at in a height-h binary search tree, k suc

2条回答
  •  萌比男神i
    2021-02-06 10:03

    Hint: work out a small example, observe the result, try to extrapolate the reason.

    To get started, here are some things to consider.

    Start at a certain node, k succesive calls to Tree-Succcesor consititutes a partial tree walk. How many (at least and at most) nodes does this walk visit? (Hint: Think about key(x)). Keep in mind that an edge is visited at most twice (why?).

    Final hint: The result is O(2h+k).

提交回复
热议问题