2

Hi I'm trying to solve the following equation with master theorem:

T(n) = a ; for n<= 2

T(n) = T(√n) + a; else

As I found a similar equation (Solving the recurrence T(n) = 2T(sqrt(n))) I'm wondering whether my solution is correct. I got T(n) = O(log log n). Is this correct for my equation above?

Code Orbit
  • 21
  • 1
  • 2
  • Possible duplicate of [Big-O notation of T(sqrtn) + 5](https://stackoverflow.com/questions/46512894/big-o-notation-of-tsqrtn-5) – meowgoesthedog Dec 22 '17 at 16:09

1 Answers1

1

We can write down a table and look for a pattern:

n        T(n)
-        ----
2        a
4        T(2)  + a = 2a
16       T(4)  + a = 3a
256      T(16) + a = 4a
...
2^(2^k)  (k+1)a

We noticed 2 = 2^(2^0), 4 = 2^(2^1), 16 = 2^(2^2), and so on; by starting with two and squaring over and over, we get terms like 2^(2^k) for which the corresponding values of T(n) are simply (k+1)a.

Given that n = 2^(2^k) and T(n) = (k+1)a, we can solve the first of these equations for k in terms of n and then substitute in the second. We get that log log n = k and so T(n) = (1 + log log n)a, which has the asymptotic bound you are after.

Technically, to complete this argument, we must note that T(n) is a monotonically non-decreasing function and so it is sufficient that we have shown the function is bounded in this way for this particular sequence of values of n. In general, a function might behave in such a way that the above method of analysis might be fooled into suggesting an inaccurate bound. For well-behaved functions this will not typically occur.

Patrick87
  • 27,682
  • 3
  • 38
  • 73