-1
void yash(){ 

    int i,j;
    for(i=1;i<=n;i++)
       for(j=1;j<=log(i);j++)
          printf("Hello !!");
}

what will be the complexity of this function?

Yash Badia
  • 11
  • 3

1 Answers1

2

Loop will iterate like this-

  • 1 * log(1) time.
  • 2 * log(2) times.
  • so on and so forth till n * log(n) times.

Among all these values, n * log(n) is the highest(upper bound). So, time complexity is n * log(n) asymptotically.

UPDATE:

If you are calculating log(i) for each iteration instead of storing it in a variable, then time complexity is O(n * log(n) 2), assuming calculating log(i) isn't O(1). If it's O(1), then time complexity is O(n log(n)).

nice_dev
  • 17,053
  • 2
  • 21
  • 35