for(int i=0;i<n;i++)
{
if(i%2==0)
{
for(int j=i;j<n;j++)
cout<<j;
}
}
is the time complexity is O(n^2)
?
for(int i=0;i<n;i++)
{
if(i%2==0)
{
for(int j=i;j<n;j++)
cout<<j;
}
}
is the time complexity is O(n^2)
?
Yes, the execution time is quadratic in n
, so it's O(n2).
By the way, you could have written this as
for(int i=0;i<n;i+=2)
for(int j=i;j<n;j++)
cout<<j;