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?
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?
Loop will iterate like this-
1 * log(1) time.2 * log(2) times.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)).