Search code examples
recursiontime-complexityasymptotic-complexity

Time complexity of the following recursive function


What is the time complexity of the following recursive function

int DoSomething(int n){
     if(n<=2) 
        return 1;
     else 
        return (DoSomething(floor(sqrt( n) )) + n);
}

Options are:-

  1. O(n^2)
  2. O(n log n) //all logs are with base 2
  3. O(log n )
  4. O(log log n )

Solution

  • The time complexity function is (ignoring floor as it is asymptotically irrelevant):

    enter image description here

    We need to find m when the algorithm terminates, i.e. when:

    enter image description here