Reccurrence T(n) = T(n^(1/2)) + 1

允我心安 提交于 2019-11-28 10:18:06

hint: assume n = 22m or m = log2log2n, and you know 22m-1 * 22m-1 = 22m so, if you define S(m)=T(n) your S will be:

S(m) = S(m-1)+1 → S(m) = Θ(m) → S(m)=T(n) = Θ(log2log2n)

extend it for the general case.

In recursion like T(n) = T(n/2) + 1, in each iteration, we reduce the height of the tree to half. This leads to Θ(logn). In this case, however, we divide the input number by a power of two (not by two) so it turns out to be Θ(log log n ).

Salvador Dali

Here is how you can find the answer without any hints, just by using math.

Start unrolling the recursion:

.

The recursion will at some point stop, so we have to find a reasonable stopping point. Trying 0, 1, 2, you can see that 2 looks good, because you can easily solve the equation:

.

Solving it, you get

.

So the recursion will continue log(log(n)) times and this is your time complexity.

P.S. a little bit harder recurrence was solved here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!