retagged by
1,500 views
1 votes
1 votes
void fun()
{
   int i, j;
   for (i=1; i<=n; i++)
      for (j=1; j<=log(i); j++)
         printf("GeeksforGeeks");
}

Soln--> thetha(nlogn)

 

Anyone please explain me in detail how to solve log series problems and what are the prerequisites to solve log problems.As i get Stuck in log problems.Please Help!

 

Thanks

retagged by

1 Answer

Best answer
2 votes
2 votes
First thing you need to watch solving these type of problems is,

see whether loop variables are independent or dependent

now as in this qsn we see inner loop  is depending on outer loop variable i

Inner loop when i=1 in worst case can execute log1 times

inner loop when i=2  in  worst case can execute log2 times

....similarly upto n

you will have series like this-log1+log2+log3+log4+log5+log6+.......logn=lo(1*2*3.......*n)=log(n!)

now you should know that log(n!)<=O(nlogn)

so your answer would be nlogn
selected by

Related questions

3 votes
3 votes
1 answer
2
Sanjay Sharma asked Feb 20, 2018
1,131 views
An array A is of length n has log( n) distinct numbers.What is the time complexity of sorting A by best comparison based algorithm ?
0 votes
0 votes
0 answers
3
Akriti sood asked Dec 27, 2016
371 views
in an effort to make MERGE-SORT faster, you decide to divide the array into k equal sized, disjoint subarrays, where k 2. This means that you have to merge k lists. How ...
2 votes
2 votes
1 answer
4