Lecture 1:a. Correctnes b. Applets c. Tables Lecture 2 a.Applets b.Tables c.Exercises Lecture 3Lecture 4a. Appletsb. ProblemsLecture 5 Lecture 6 Lecture 7 Lecture 8 Test 1 Test 2

Solve 7.25,7.26 and 7.27 form Algorithms and Data Structures : The Science of Computing available from Ebrary.

7.25 Consider the following alternative to this chapter's powerOf2 algorithm:

public static long otherPowerOf2(int n){

if (n > 0) {

long lowerPower = otherPowerOf2(n - 1);

return lowerPower + lowerPower;

}

else{

return 1 ;

}

}

Estimate the execution time of this algorithm.

7.26 Redo the analysis of powerOf 2's execution time, counting

1. The n > 0 comparisons as well as the additions
2. The n > 0 comparisons and the subtractions as well the additions

Do these more complete analyses still suggest execution times more or less proportional to 2n, or do the times become even worse?

7.27 What function of x does the following algorithm compute (assume x is a natural number)?

public static int mystery(int x) {
if (x > 0) {

return mystery(x-1) + 2*x - 1;

}
else {

return 0;

}
}

(Hint: The algorithm practically is a recurrence relation for the function it computes. Write this recurrence explicitly, and then find a closed form for it.)

Algorithms | Blackboard | UNAL | SIA |Bibliotecas|UNALdotNET

Hosted by www.Geocities.ws

1