CMSC 441: Homework #1 Solutions - Inspiring Innovationnam1/TA/HWSols/hw1sol.pdf · Parag Namjoshi...

4
CMSC 441: Homework #1 Solutions Parag Namjoshi 1

Transcript of CMSC 441: Homework #1 Solutions - Inspiring Innovationnam1/TA/HWSols/hw1sol.pdf · Parag Namjoshi...

Page 1: CMSC 441: Homework #1 Solutions - Inspiring Innovationnam1/TA/HWSols/hw1sol.pdf · Parag Namjoshi CMSC 441 Homework #1 Solutions Exercise 3.1–2 Exercise 3.1–2 Show that for any

CMSC 441: Homework #1 Solutions

Parag Namjoshi

1

Page 2: CMSC 441: Homework #1 Solutions - Inspiring Innovationnam1/TA/HWSols/hw1sol.pdf · Parag Namjoshi CMSC 441 Homework #1 Solutions Exercise 3.1–2 Exercise 3.1–2 Show that for any

Parag Namjoshi CMSC 441 Homework #1 Solutions Exercise 3.1–2

Exercise 3.1–2

Show that for any real constants a and b, where b > 0,

(n + a)b = Θ(nb)

Solution:

(n + a)b ≤ (n + |a|)b, where n > 0

≤ (n + n)b for n ≥ |a|

= (2n)b

= c1 · nb, where c1 = 2b

Thus

(n + a)b = Ω(nb). (1)

(n + a)b ≥ (n − |a|)b, where n > 0

≥ (c′2n)b for c′2 = 1/2 where n ≥ 2|a|

as n/2 ≤ n − |a|, for n ≥ 2|a|

Thus

(n + a)b = O(nb) (2)

The result follows from 1 and 2 with c1 = 2b, c2 = 2−b, and n0 ≥ 2|a|.

Exercise 3.1–4

Is 2n+1 = O(2n) ? Is 22n = O(2n)?

Solution:

(a)

Is 2n+1 = O(2n) ? Yes.

2n+1 = 2 2n ≤ c2n where c ≥ 2.

(b)

Is 22n = O(2n) ? No.

22n = 2n · 2n. Suppose 22n = O(2n). Then there is a constant c > 0 such that c > 2n. Since 2n is

unbounded, no such c can exist.

Page 2 of 4

Page 3: CMSC 441: Homework #1 Solutions - Inspiring Innovationnam1/TA/HWSols/hw1sol.pdf · Parag Namjoshi CMSC 441 Homework #1 Solutions Exercise 3.1–2 Exercise 3.1–2 Show that for any

Parag Namjoshi CMSC 441 Homework #1 Solutions Exercise 3.1–7

Exercise 3.1–7

Prove that o(g(n)) ∩ ω(g(n)) is the empty set.

Solution:

Suppose not. Let f(n) ∈ o(g(n)) ∩ ω(g(n)) Now f(n) = ω(g(n)) if and only if g(n) = o(f(n)) and

f(n) = o(g(n)) by assumption. By transitivity property (page 49), f(n) = o(f(n)) i.e. for all constants

c > 0, f(n) < cf(n). Choose c < 1 and we have the desired contradiction from the asymptotic nonnegativity

of f(n).

Exercise 3.1–8

We can extend our notation to the case of two parameters n and m that can go to infinity independently at

different rates. For a given function g(n, m), we denote by O(g(n, m)) the set of functions

O(g(n, m)) = f(n, m) : there exist positive constants c, n0, and m0 such that 0 ≤ f(n, m) ≤ cg(n, m) for

all n ≥ n0 and m ≥ m0 .

Give corresponding definitions for Ω(g(n, m)) and Θ(g(n, m))

Solution:

Ω(g(n, m)) = f(n, m) : there exist positive constants c, n0, and m0 such that 0 ≤ cg(n, m) ≤ f(n, m) for

all n ≥ n0 and m ≥ m0 .

Θ(g(n, m)) = f(n, m) : there exist positive constants c1, c2, n0, and m0 such that c1g(n, m) ≤ f(n, m) ≤

c2g(n, m) for all n ≥ n0 and m ≥ m0 .

Exercise 3.2–1

Show that if f(n) and g(n) are monotonically increasing functions, then so are f(n)+ g(n) and f(g(n)), and

if f(n) and g(n) are in addition nonnegative, then f(n) · g(n) is monotonically increasing.

Solution:

(a)

We must show that if f(n) and g(n) are monotonically increasing functions, then so is f(n) + g(n).

Suppose not. Let n1 < n2 and f(n1)+g(n1) > f(n2)+g(n2). Now, f(n1) ≤ f(n2) and g(n1) ≤ g(n2)

f(n1) ≤ f(n2)

f(n1) + g(n1) ≤ f(n2) + g(n1)

f(n1) + g(n1) ≤ f(n2) + g(n2)

This contradicts our assumption.

(b)

We must show that if f(n) and g(n) are monotonically increasing functions, then so is f(g(n)).

Suppose not. Let n1 < n2 and f(g(n1)) > f(g(n2)). Let m1 = g(n1), m2 = g(n2). m1 ≤ m2. Clearly,

Exercise 3.2–1 [(b)] continued on next page. . . Page 3 of 4

Page 4: CMSC 441: Homework #1 Solutions - Inspiring Innovationnam1/TA/HWSols/hw1sol.pdf · Parag Namjoshi CMSC 441 Homework #1 Solutions Exercise 3.1–2 Exercise 3.1–2 Show that for any

Parag Namjoshi CMSC 441 Homework #1 Solutions Exercise 3.2–1

f(m1) ≤ f(m2), which contradicts our assumption.

(c)

We must show that if f(n) and g(n) are monotonically increasing functions, then so is f(n)g(n))

if f and g are nonnegative. Suppose not. Let n1 < n2 and f(n1) + g(n1) > f(n2) + g(n2). Now,

f(n1) ≤ f(n2) and g(n1) ≤ g(n2)

f(n1) ≤ f(n2) (3)

f(n1)g(n1) ≤ f(n2)g(n1) (4)

f(n1)g(n1) ≤ f(n2)g(n2) (5)

This contradicts our assumption. Note that 4 and 5 hold since f and g nonnegative,

Page 4 of 4