You are on page 1of 6

Math 2320M Midterm Exam

Instructor: A. Premat February 8th, 2006

Name:

ID number:

NO BOOKS, CALCULATORS OR NOTES ARE PERMITTED.

Question Value Marks


Q1 (a) 2
(b) 2
(c) 6
Q2 (a) 3
(b) 3
(c) 4
Q3 (a) 2
(b) 4
(c) 4
Q4 (a) 5
(b) 5
Q5 (a) 3
(b) 3
(c) 4
Total 50
Math 2320M Midterm 1 2

Question 1.

(a) Let f : A → B be a function. Define what it means for f to be


one-to-one.

f is said to be one-to-one if, for a, b ∈ A, f (a) = f (b) implies a = b.

(b) Let f : A → B be a function. Define what it means for f to be onto.

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.

(c) Show that the function f : Z → Z defined by f (n) = b n2 c + 3 is onto


but not one-to-one.

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

Question 2. A palindrome is a string of letters that reads the same for-


ward and backward. For example MADAM is a palindrome but MAN is not.
The following algorithm determines if a string of n letters is a palindrome.

procedure palindrome check (a1 a2 ...an : string of letters)


answer:=true
for i := 1 to b n2 c
if ai 6= an+1−i then answer:=false
{answer is true iff the string is a palindrome}

(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.

(b) What is the number of comparisons required to execute the algorithm


in the worst-case scenario when the input string has length n?

The worst-case scenario is when the word is a palindrome. In this case


the algorithm will require 2b n2 c+1 comparisons (two comparisons every
time it goes through the loop and one comparison to exit it).

(c) What is the worst-case time complexity of the algorithm?

The worst-case time complexity of the algorithm is O(n).


Math 2320M Midterm 1 4

Question 3.

(a) Let f : R → R and g : R → R.


Define what it means for f (x) to be O(g(x)).

f (x) is O(g(x)) if there exists constants k and C such that

|f (x)| ≤ C|g(x)| for all x > k.

(b) Let f : R → R be defined by f (x) = 2x+dxe. Show from the definition


that f (x) is O(x).

|f (x)| = |2x + dxe|


= 2x + dxe if x > 0
≤ 2x + x + 1
≤ 2x + x + x if x > 1.
Hence |f (x)| ≤ 4x = 4|x| if x > 1.

(c) Let f : R → R be defined by f (x) = 2x2 + x. Show that f (x) is NOT


O(x).

Suppose f (x) is O(x). Then there exists constants C and k such that

|2x2 + x| ≤ C|x| for allx > k.

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

Hence gcd(206, 94) = 2.

(b) Find integers s and t such that 206 s + 94 t = gcd(206, 94).

2 = 18 − 4(4)
= 18 − (94 − 18(5))(4)
= 21(18) − 4(94)
= 21(206 − 94(2)) − 4(94)
= 21(206) − 46(94)

Hence we can choose s = 21 and t = −46.


Math 2320M Midterm 1 6

Question 5.

(a) Let a and b be integers and m an odd integer. Prove that


if 2 a ≡ 6 b (mod m) then a ≡ 3b (mod m).

2 a ≡ 6 b (mod m) implies m|(2a − 6b), i.e m|2(a − 3b). Since m is odd,


gcd(m, 2) = 1; hence m|(a − 3b), i.e. a ≡ 3b (mod m).

(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.

Suppose a is even and b is odd. Then a = 2m and b = 2n + 1 for some


integers m and n. Hence a − b = 2m − (2n + 1) = 2(m − n) − 1. So
1 = 2(m − n) − (a − b). Since 2|(a − b) and 2|2(m − n), 2|1. This is a
contradiction; hence a cannot be even if b is odd. Similarly b cannot
be even if a is odd. Therefore either both a and b are even or both
odd.

(c) Let a and b be positive integers. If a is even, a ≤ b, gcd(a, b) = 15


and lcm(a, b) = 105, what are a and b?

There are no integers a and b satisfying all the conditions since if a is


even, 2 would divide lcm(a, b), but 2 6 | 105.

You might also like