------------------------------------------------------------------------------ Mohamed G. Gouda CS 311 Spring 2015 Midterm 3 ------------------------------------------------------------------------------ 1. (5 points) Prove the predicate (A sub B) => (A = (A^B)) where A and B are sets and ^ denotes the intersection set operator. ------------------------------------------------------------------------------- 2. (5 points) Let f(n) and g(n) be the following two functions. f(n) = 2(n^2) g(n) = (n^3) - 2(n^2) Solve either (a) or (b) below: (a) Prove that f(n) is O(g(n)). (b) Prove that g(n) is Omega(f(n)). ------------------------------------------------------------------------------ 3. (5 points) Verify that the following program Specification is true (T) x := x+y (x+1 > y) where T is the predicate "true" and x and y are variables of the program of type nonnegative integers. ----------------------------------------------------------------------------- 4. (5 points) Let f:A->A be a function where A is the set of all nonnegative integers and f(x) = max(x-1, 0). Show that f(x) is not injective. ------------------------------------------------------------------------------ Solutions ------------------------------------------------------------------------------ 1. x in A <=> {A sub B} (x in A) and (x in B) <=> {definition of ^} (x in A^B) ----------------------------------------------------------------------------- 2. (a) |f(n)| = |2(n^2)| = 2(n^2) for n > 0 =< 2(n^2) * (n-2) for n > 2 = 2((n^3) - 2(n^2)) = C*(g(n)) for C = 2 = C*|g(n)| for K=2 and C=2 (b) |g(n)| = |(n^3) - 2(n^2)| = ((n^3) - 2(n^2)) for n > 2 >= (4(n^2) - 2(n^2)) for n > 4 = 2(n^2) = C*(2(n^2)) for C = 1 = C*|f(n)| for K=4 and C=1 ------------------------------------------------------------------------------- 3. We need to prove the following predicate: (All nonengative integers x and y, (T) => (x+y+1 > y)) A direct inference proof of this predicate is as follows: T => (x >= 0) and (y >= 0) => (x+y) >= y => (x+y+1) > y ---------------------------------------------------------------------------- 4. We can use the "guessing proof style" to prove that f(x) is not injective. Guess two nonnegative integers x1 and x2 such that f(x1)=f(x2) and x1=!x2. The guessed x1 and x2 are 0 and 1. ----------------------------------------------------------------------------