How to determine the height of a recursion tree fr

2020-06-03 02:10发布

How does one go about determining the height of a recursion tree, built when dealing with recurrence run-times? How does it differ from determining the height of a regular tree?

alt text http://homepages.ius.edu/rwisman/C455/html/notes/Chapter4/ch4-9.gif

edit: sorry, i meant to add how to get the height of the recursion tree from the recurrence relation.

4条回答
爷、活的狠高调
2楼-- · 2020-06-03 02:46

The height of the recursion tree depends on the recursive algorithm in question. Not all divide and conquer algorithms have uniformed height trees, just as not all tree structures have uniform heights. If you cannot determine the maximum possible height of the algorithm, or if you need to calculate the actual height of the tree at run time, you can use a variable global to the recursive function, increment it upon the entry to the function, and decrement it upon the function exit. This variable will indicate the current level of the recursive procedure. If necessary, you can maintain the maximum value of this variable in a second variable.

查看更多
甜甜的少女心
3楼-- · 2020-06-03 02:51

The depth of any tree is the smallest number of edges from the node to the tree root node.The depth of root node is 0.

Consider the recursion T(n)=aT(n/b) It results in the following recursion tree

enter image description here

It is clear that depth of tree is $\log_b n$ Depth is same as height of a tree.

查看更多
兄弟一词,经得起流年.
4楼-- · 2020-06-03 02:58

If recurrence is in the form of T(n) = aT(n/b) + f(n) then the depth of the tree is log base b of n.

For example, 2T(n/2) + n recurrence would have tree of depth lg(n) (log base 2 of n).

查看更多
爷、活的狠高调
5楼-- · 2020-06-03 03:07

Firstly, if this is a homework question, please mark it as such. The images you link to imply that you're in CS 455, with Professor Wisman. :)

The main hint I'll give is this: The height of the tree is obviously determined by when you get to the "leaves". The leaves of a tree modelling the recurrence relation of a function are the base case. Thus, I would look towards seeing how "quickly" N can shrink to the base case.

查看更多
登录 后发表回答