Please can anybody tell me that is there any difference in time complexity for printing an array using two different methods

Suppose I has to print an Array of size 1000 then is there any difference in time taken by this two loops in print every no:

first loop:
for(i=0;i<1000;i++)
{
cout<<arr[i]<<endl;
}

Second Loop:
for(i=0;i<1000;i+=5)
{
cout<<arr[i]<<endl;
cout<<arr[i+1]<<endl;
cout<<arr[i+2]<<endl;
cout<<arr[i+3]<<endl;
cout<<arr[i+4]<<endl;
}

Thanks in Advance

1 Like

Both are same suppose x is time taken to cout so in above loop u doing 1000x work and in below 200 times 5x

The complexity tells how fast the running time of algorithm increases with increase in size of input. We call the input size N.
In this case, N is the size of array. The first loop is O(N) and the second loop is O(N/5), however constants in time complexity do not contribute to the growth of running time, so we consider only the highest power of the varying term, N in our case and we drop the constant term 5. Thus both loops are O(N).

2 Likes