Time execution

for a time limit of 1 sec ,what is the maximum number of loops that i can expect to have in a
program (neglecting the effect of fast input/output)?

2 Likes

It depends on the time complexity of the algorithm you are using. Mostly prefer the algorithm/program whose time complexity comes to O(n). Sometime algo with complexity O(n^2) can also be accepted. Basically it depends on the size of input you need to process.

You can have one loop or 100 loops. It doesnt matter. The only thing you need to know is that the number of computations in a second is roughly 10^8 to 10^9. So if a single loop runs upto say 100 , you can have 4 such loops.

2 Likes

@pranay2063 No. of computations is nothing but the no. of times your statement (basic operation) in the innermost loop executes.
For example:

for(i=0;i<100;i++)
{
     for(j=0;j<100;j++)
      {
          for(k=0;k<100;k++)
          {
               basic-operation;
          }
     }
}

In this the no. of computation comes to 10^6.

1 Like

what does this term ‘computation’ exactly mean? is number of computations and number of loops being executed in a program ,mean the
same thing?