but each time the cost of the inner loop is different because it costs with changing each time you should see that for the first execution of the outer loopi is for the second execution of the outer loopi is each time through the outer loopi becomes one greateruntil the last time through the loop when thusthe total cost of the loop is times the sum of the integers through from equation we know that = in( which is th( by simplifying rule ( )th( is simply th( example compare the asymptotic analysis for the following two code fragmentssum for ( = <=ni++for ( = <=nj++sum ++/first double loop /do times sum for ( = <=ni++for ( = <=ij++sum ++/second double loop /do times in the first double loopthe inner for loop always executes times because the outer loop executes timesit should be obvious that the statement sum +is executed precisely times the second loop is similar to the one analyzed in the previous examplewith cost nj= this is approximately thusboth double loops cost th( )though the second requires about half the time of the first example not all doubly nested for loops are th( the following pair of nested loops illustrates this fact