

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Make sure you show all you work and start early.
From “Data Structures, Algorithms, and Software Principles in C”
Also do these problems
1
==
nn n i
n
i
a. sum=0; for (i=0; i<n; i++) sum++;
b. sum=0; for (i=0; i<n; i++) for (j=0; j<n; j++) sum++;
c. sum=0; for (i=0; i<n; ++i) for (j=0; j <n*n; ++j) sum++
d. sum=0; for (i=0; i<n; ++i) for (j=0; j<i; ++j) sum++;
e. sum=0; for (i=0; i<n; ++i) for (j=0; j<i*i; ++j) for (k=0; k <j; ++k) sum++;
f. sum=0; for (i=1; i<n; ++i) for (j=1; j<i*i; ++j) if (j%i == 0) for (k=0; k<j; ++j) sum++;
Extra Credit Problem
The Sieve of Erastothenes is a method used to compute all primes less than. We begin by making a table of integers from 2 to n. We find the smallest integer, i that is not
crossed out, print i , and cross out i , 2i, 3i ,…. When
n
i > n , the algorithm terminates. What is the running timer of this algorithm?