I have a program and am trying to calculate its complexity. I want to be sure that I’m not mistaken.
for(int i=4; i<=n; i=i*4)
{
cout<<"counter for first loop: "<<++count1<<endl;
for(int j=i;j>=0;j=j-4)
{
cout<<"counter for second loop: "<<++count2<<endl;
for(int k=0;k<=n;k++)
{
cout<<"counter for third loop: "<<++count3<<endl;
}
}
}
Here the complexity of the third cycle is O (n), then together with the second cycle the complexity becomes O (n.log 4i), and the complexity of the entire program is O (p. (enter <sub> 4sub> i) 2 ). Am I right in my answer? Thanks
user2110714
source
share