edited by
414 views
0 votes
0 votes
What will be the time complexity?

voidfun()

{

int i, j;

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

for (j=1; j<=log(i); j++)

printf("hello");

}
edited by

1 Answer

Best answer
1 votes
1 votes

Here we have to analyse like this :

For ith value ,  the inner loop runs log(i) times.

So say when i  =  2 , the inner loop runs  log(2) times ,  when i = 3 , the inner loop runs log(3) times and so on till i = n..

So time complexity  =  log(1) + log(2) + log(3) ........ + log(n)

                              =  log(1.2.3.....n)

                              =  log(n!)

                              =  nlogn - n + O(logn)  = nlogn      [  By Stirling's approximation and considering the dominant term ]

                              =  θ(nlogn)

Hence time complexity   =   θ(nlogn)

edited by

Related questions

1 votes
1 votes
0 answers
1
srestha asked May 19, 2019
644 views
Let $A(n)$ denotes the number of $n$ bit binary strings which have no pair of consecutive $1’s.$ what will be recurrence relation for it and what will be it’s Time Co...
0 votes
0 votes
1 answer
2
eyeamgj asked Jun 24, 2018
411 views
consider the following c program A(n){if(n<=1)return(n2 +n+1)elsereturn(5A(n/2)+3A(n/2)+MA(n))}where MA(n) has complexity O(n2).1.what is the recurrence relation for valu...
1 votes
1 votes
1 answer
3
nikkey123 asked Jan 3, 2018
417 views
0 votes
0 votes
1 answer
4
Surya Dhanraj asked Oct 24, 2017
496 views
An array a of unknown size is filled with special symbol let's say # . Time required to find the size of a is:Please give proper explanation