
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information about the homework assignment for cs 2233 discrete mathematical structures course offered in the fall of 2008. The assignment includes various exercises related to loop invariants, recursive sequences, and weak induction. Students are required to use the textbook 'rosen, 6th edition' for reference.
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Due 10/27/08 before class
Please refer to the corresponding exercise sections in the textbook (Rosen, 6th edition).
4.5 • (4 points) Use the loop invariant (I) : power = 2k^ to show that the code below correctly computes 2n^ for any n ≥ 0. First, use induction to show that (I) is indeed a loop invariant, and then draw conclusions for the termination of the while loop.
int power_of_two(int n){ int power=1; int k=0; while(k<n){ // (I) power=2^k k++; power = power*2; } return power; }
4.3 (page 308)
4.4 (page 321)
int factorial(int n){ if(n==0) return 1; return factorial(n-1)*n; }