CS 2233 Discrete Mathematical Structures Fall 08 Homework, Assignments of Discrete Mathematics

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

Pre 2010

Uploaded on 07/30/2009

koofers-user-j8p
koofers-user-j8p 🇺🇸

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 2233 Discrete Mathematical Structures Fall 08
10/15/08
5. Homework
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 = 2kto show that the code
below correctly computes 2nfor any n0. 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)
(6 points) 8 a,b,c. First write down the first six elements of the sequence,
and then try to find a recursive definition. Do not forget the base case.
(3 points) 12. Use (weak) induction.
(2 points) 24 a,b.
4.4 (page 321)
(2 points) 8
(2 points) 10
c) (3 points) Use weak induction on nto prove that factorial(n) correctly
computes n!, when nis a non-negative integer.
int factorial(int n){
if(n==0)
return 1;
return factorial(n-1)*n;
}

Partial preview of the text

Download CS 2233 Discrete Mathematical Structures Fall 08 Homework and more Assignments Discrete Mathematics in PDF only on Docsity!

CS 2233 Discrete Mathematical Structures – Fall 08

5. Homework

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)

  • (6 points) 8 a,b,c. First write down the first six elements of the sequence, and then try to find a recursive definition. Do not forget the base case.
  • (3 points) 12. Use (weak) induction.
  • (2 points) 24 a,b.

4.4 (page 321)

  • (2 points) 8
  • (2 points) 10 c) (3 points) Use weak induction on n to prove that factorial(n) correctly computes n!, when n is a non-negative integer.

int factorial(int n){ if(n==0) return 1; return factorial(n-1)*n; }