edited by
1,206 views
0 votes
0 votes
what is the time complexity of

function(int n)

{

         if(n<=1) return;

         for(int i=1; i<n; i++)

         {

                     printf("*");

         }
                     function(0.8n);

         

}

i'm getting O(nlogn base 5/4) using the recurrence relation method but in the book it's given O(n)

$T(n)=T(\frac{4n}{5})+O(n)$
edited by

1 Answer

0 votes
0 votes
Using the recurrence, you should get it as $O(n)$.

After $k$ iterations, this is what the recurrence would look like:

$T(n) = T((\frac{4}{5})^k n) + cn(1 + 4/5 + 16/25  + \dots + (\frac{4}{5})^k)$

$\,\,\,\,\,\,\,\,\,\,\,\, \,\,\,\leq T((\frac{4}{5})^k n) + cn(1 + 4/5 + 16/25  + \dots \infty)$

which is an infinite GP with $a = 1$ and $d = 4/5$.

Therefore, your recurrence becomes:

$T(n) = 1 + 5cn$ which is $O(n)$

Related questions

0 votes
0 votes
2 answers
1
aditi19 asked Nov 4, 2018
825 views
0 votes
0 votes
0 answers
2
aditi19 asked Nov 6, 2018
342 views
f(n)=$2^n$g(n)=n!h(n)=$n^{logn}$ which one is true?A) f(n)=O(g(n)) and g(n)=O(h(n))B) f(n)=$\Omega(g(n)))$ and g(n)=O(h(n))C) g(n)=O(f(n)) and h(n)=O(f(n))D) h(n)=O(f(n))...