Professional Documents
Culture Documents
Name:
ID number:
Question 1.
f is onto if the range of f equals the codomain of f , i.e. if, for each
b ∈ B, there exists an a ∈ A such that f (a) = b.
f is not one-to-one:
For example f (0) = 3 = f (1).
f is onto:
Let m ∈ Z. We need to find an n ∈ Z such that f (n) = m. Let
n = 2(m − 3) ∈ Z, then
2(m − 3)
f (n) = f (2(m − 3)) = b c + 3 = m − 3 = m.
2
Math 2320M Midterm 1 3
(a) List all the steps of the algorithm if the input is MADAM.
answer:=true
i := 1, if i ≤ b 52 c = 2, compare a1 = M with a5 = M .
i := 2, if i ≤ b 52 c = 2, compare a2 = A with a4 = A.
i := 3, if i ≤ b 52 c = 2, stop.
Question 3.
Suppose f (x) is O(x). Then there exists constants C and k such that
Then
2x2 + x ≤ Cx for all x > k and x > 0
x(2x + 1) ≤ Cx for all x > k and x > 0
2x + 1 ≤C for all x > k and x > 0
x ≤ C−1
2 for all x > k and x > 0
This is not possible since C is a constant. Hence f (x) is NOT O(x).
Math 2320M Midterm 1 5
Question 4.
(a) Use the Euclidean algorithm to find the greatest common divisor of
206 and 94.
206 = 94(2) + 18
94 = 18(5) + 4
18 = 4(4) + 2
4 = 2(2) + 0
2 = 18 − 4(4)
= 18 − (94 − 18(5))(4)
= 21(18) − 4(94)
= 21(206 − 94(2)) − 4(94)
= 21(206) − 46(94)
Question 5.
(b) Let a and b be integers. Prove that if a ≡ b (mod 2) then either both
a and b are odd or both a and b are even.