Solving the recurrence T(n) = 2T(sqrt(n))

别来无恙 提交于 2020-01-24 06:00:23

问题


I would like to solve the following recurrence relation:

T(n) = 2T(√n);

I'm guessing that T(n) = O(log log n), but I'm not sure how to prove this. How would I show that this recurrence solves to O(log log n)?


回答1:


One idea would be to simplify the recurrence by introducing a new variable k such that 2k = n. Then, the recurrence relation works out to

T(2k) = 2T(2k/2)

If you then let S(k) = T(2k), you get the recurrence

S(k) = 2S(k / 2)

Note that this is equivalent to

S(k) = 2S(k / 2) + O(1)

Since 0 = O(1). Therefore, by the Master Theorem, we get that S(k) = Θ(k), since we have that a = 2, b = 2, and d = 0 and logb a > d.

Since S(k) = Θ(k) and S(k) = T(2k) = T(n), we get that T(n) = Θ(k). Since we picked 2k = n, this means that k = log n, so T(n) = Θ(log n). This means that your initial guess of O(log log n) is incorrect and that the runtime is only logarithmic, not doubly-logarithmic. If there was only one recursive call being made, though, you would be right that the runtime would be O(log log n).

Hope this helps!




回答2:


You can solve this easily by unrolling the recursion:

Now the recurrence will finish when T(1) = a and you can find the appropriate a. When a = 0 or 1 it does not make sense but when a=2 you will get:

Substituting the k into latest part of the first equation you will get the complexity of O(log(n)).

Check other similar recursions here:

  • T(n) = 2T(n^(1/2)) + log n
  • T(n) = T(n^(1/2)) + Θ(lg lg n)
  • T(n) = T(n^(1/2)) + 1


来源:https://stackoverflow.com/questions/18098337/solving-the-recurrence-tn-2tsqrtn

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