SUNY Geneseo Department of Computer Science
CSci 240, Spring 2007
Prof. Doug Baldwin
Due Wednesday, March 21
Derive expressions for the number of multiplication operations each of the following iterative algorithms executes, in terms of n.
for ( int i = 0; i < n; i++ ) {
sum = sum + i * i;
}
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < n; j++ ) {
table[i][j] = i * j;
}
}
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < i; j++ ) {
table[i][j] = i * j;
}
}
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < i; j++ ) {
totalProd = totalProd * i * j;
}
}
for ( int i = 0; i < n; i++ ) {
int limit = i * n;
for ( int j = 0; j < n; j++ ) {
for ( int k = 0; k < limit; k++ ) {
System.out.println( j * k );
}
}
}
I will grade this exercise in a face-to-face meeting with you. Make an appointment to meet with me at some time convenient for you, as long as that time is before the end of the due date above. Meetings only need to be 15 minutes long. You can make an appointment by signing up on the copy of my schedule on the bulletin board outside my office. Please bring written written derivations for ach algorithm to the meeting.