Occasionally multiplying the sizes of nested loops can give


Question: Occasionally, multiplying the sizes of nested loops can give an overestimate for the Big-Oh running time. This result happens when an innermost loop is infrequently executed. Repeat Exercise for the following program fragment:

for( int i = 1; i <= n; i++ )

    for( int j = 1; j <= i; j++ )

          if( j % i == 0)

              for( int k = 0; k < j; k++ )

                   sum++;

Exercise: For each of the following program fragments, do the following:

a. Give a Big-Oh analysis of the running time.

b. Implement the code and run for several values of N.

c. Compare your analysis with the actual running times.

2364_4.jpg

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Occasionally multiplying the sizes of nested loops can give
Reference No:- TGS02457557

Now Priced at $15 (50% Discount)

Recommended (95%)

Rated (4.7/5)