[Hernandez 1213A] Cs30 day7

Page 1

CS 30

First Long Examination

Reviewer

p → (q ∧ r) ≡ (p → q) ∧ (∼ p ∨ r)

1) Use a truth table to prove that

2) Convert the statements into symbolic notations then test the validity of the argument using the rules of inference: If I study, then I will not fail mathematics. If I do not study then I will play computer games. I failed mathematics. ——————————————————————– Therefore I must have played computer games. 3) A Mersenne prime is a prime number which can be written as one less than a power of two. (a) Find three Mersenne primes, that is, primes of the form 2n − 1 for some positive integer n. (b) Prove by contraposition that if 2n − 1 is prime then n is prime. (Hint: x − y is a factor of xn − y n , for any positive integer n.)

(c) Prove that the converse of part (b) is false. (Hint: take n = 11.) (d) Prove by contradiction that if a and n are a positive integers such that an − 1 is prime, then either a = 2 or n = 1. (e) Prove that if 2n − 1 is a Mersenne prime, then 2n−1 (2n − 1) is a perfect number. Note: A perfect number is a positive integer that is equal to the sum of its proper positive divisors. (e.g. The proper positive divisors of 28 are 1, 2, 4, 7 and 14. 28 is a perfect number since 28 = 1 + 2 + 4 + 7 + 14.)

4) One particular algorithm used to sort a list of numbers into increasing order is heapsort. Heapsort employs a preprocessing step called heapify. It takes 0 · 2n + 1 · 2n−1 + 2 · 2n−2 + 3 · 2n−3 + · · · + (n − 1) · 21 + n · 20 steps to “heapify” a list of 2n numbers. Prove by mathematical induction that the closed form for this summation is 2n+1 − n − 2 for n ≥ 0. 5) Consider a 2n × 2n chessboard with one arbitrarily chosen square removed (an example of such a chessboard is shown at the right). Prove that any such chessboard can be completely covered without gaps or overlaps by L-shapes consisting of 3 squares each

.

6) [Pre-condition: m is a nonnegative integer, x is a real number, i = 0, and exp = 1.] while i 6= m exp := exp · x i := i + 1 end while [Post-condition: exp = xm ] loop invariant: I(n) is “exp = xn and i = n”.

an example of a 23 × 23 chessboard with one square removed

To prove the correctness of a loop with respect to its pre- and post- conditions, we may show that the four properties in the loop invariant theorem are satisfied. What are these four properties? Prove that the given loop satisfies these properties.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.