Was wondering what is the time complexity of the following code:
int i,j,n,p,s=0;
scanf("%d",&n);
p = pow(3, n);
for(i=0; i<p; i++)
{
for(j=0; j<n; j++)
{
s+=j;
}
printf("%d",i);
}
In my opinion, the time complexity will be n*(3^n).
What will it be in Big-O notation, what do you guys think ?
Yes it is O((3^n)*n)
.
Outer loop iterates 3^n
times, each time, the inner loop does O(n)
work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.