search
Log In
0 votes
66 views
what is the time complexity for this code
 

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

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

          //Do something

           }

}
in Algorithms 66 views
1

i=1 ===> j loop runs log (1) times

i=2 ===> j loop runs log (2) times

i=3 ===> j loop runs log (3) times

......

i=n ===> j loop runs log (n) times

Total time runs = log(1) + log(2) + ....+ log(n) = log (1.2.3.4.....n) = log (n!) = log(nn) = n.log(n)

1
O(nlogn) ?
0
Thank you for the explanation!

Please log in or register to answer this question.

Related questions

0 votes
1 answer
1
131 views
Finding the running time of the following algorithm. $Procedure$ $A(n)$ $\textrm{ if (n}<=\textrm{2) then return 1 ;}$ $else$ $Return(A(\left \lceil \sqrt{n} \right \rceil))$
asked May 23, 2019 in Algorithms Sachdev aprajita 131 views
3 votes
1 answer
3
669 views
Consider the following program: int Bar(int n){ if(n<2) return; } else{ int sum=0; int i,j; for(i=1;i<=4;i++) Bar(n/2); for(i=1;i<=n;i++){ for(j=1;j<=i;j++){ sum=sum+1; } } } Now consider the following statement $S_{1}:$ The time complexity of ... $S_{3}:$The time complexity of $Bar\left ( n \right )$ is $O \left ( n^{3}logn^{2} \right )$ How many statements are correct________________
asked May 7, 2019 in Algorithms srestha 669 views
0 votes
0 answers
4
368 views
What is the best case and worst case of the algorithm? And when will best case and worst case will happen?? int main() { for(i=1 ; i<=n ; i++) { if(n%i == 0) { for(j=1 ; j<=n ; j++) { printf("Hello"); } } } }
asked Apr 10, 2019 in Algorithms sumitr 368 views
...