Você está na página 1de 2

COS 250 HW #2 Due Monday September 24, 2012 11:59PM

1. (20 points) The greatest common divisor has been defined in this course and a function produced that can calculate it. Let a and b be two positive integers and g = GCD(a,b). It is always possible to find two integers s and t such that g = s*a + t*b. Note that s and t are typically not both positive. Write a recursive Python function called GCD2(a,b) that returns a list of three numbers (g,s,t) where g = GCD(a,b) and g = s*a + t*b. Be sure to include some large integers in your test runs. Submit a listing of the program along with the test runs. (15 points) Below is the definition of the famous Fibonacci function: def fib(n): if n <2: return 1 else: return fib(n-1) + fib(n-2) Using the Proof by the Principle of Recursion, show that for all n 2 2n fib(n) 2n/2 Submit a listing of the program along with the test runs. 3. (20 points) Using Induction, prove that for any natural number n 0, 11n+2 + 122n+1 is divisible by 133. (Hint: a reduction into sums like we used for other problems does not work for this problem. You should consider a scheme like the one used to solve a pair of linear equations in two unknowns. In particular, think about how you eliminate one variable from such a system of equations.) Be sure to write a program to confirm this claim for at least 20 numbers. Submit a listing of the program along with the test runs. 4. (15 points) Prove by Induction that for any natural number n 0, 1 + 2 + 22 + 23 + + 2n-1 = 2n - 1 Be sure to write a program to confirm this claim for at least 20 numbers. Submit a listing of the program along with the test runs.

2.

COS 250 Fall 2012 HW #2 Markowsky

Page 1 of 2

5.

(15 points)

Prove by the Principle of Recursion that

(1)
i =1

n +1

i = (1)

n +1

((n + 1) / 2)

Note that the division on the right side of the equation is integer division. Write a program to verify the equation for at least 20 values. Submit a listing of the program along with the test runs. 6. (15 points) Write a detailed proof of the fact that (e+(((a+b)+c)+d))+(f+(g+h)) = (b+(g+a)) + ((((c+e)+d)+f)+h) for any numbers a, b, c, d, e, f, g, and h. Each step in the proof must be justified using only the associative and commutative laws of +. For example, suppose you were asked to prove (d+a) + (b+c) = a + (b + (c+d)) The proof might look like EQUATION (d+a) + (b+c) = (a+d) + (b+c) = a + (d + (b+c)) = a + ((b+c) + d) = a + (b + (c+d)) JUSTIFICATION Commutativity Associativity Commutativity Associativity

COS 250 Fall 2012 HW #2 Markowsky

Page 2 of 2

Você também pode gostar