Docsity

CSE21 Homework Solution: Big O Notation Analysis, Assignments of Computer Science

Toggle sidebar
bg1
CSE21 HW #3 Solution
1. (20 Points) Answer whether the followings are true and prove your answer:
(a) 3
√nis O(4
√n+ log(n))
Solution
No. (2 pts)
Proof (2 pts) Suppose that 3
√nis O(4
√n+log(n)). By the supposition that 3
√nis O(4
√n+
log(n)), there exists a positive real number Band a real number bsuch that for all integers
n > b
|3
√n| ≤ B|4
√n+ log(n)|(1)
Let nbe a positive integer that is greater than max{(2B)12,216,b}. Then
n > (2B)12 =⇒ | 3
√n|=12
√n4
√n > 2B4
√n
4
√n > log(n) for all integers n > 216 =⇒2B4
√n > B(4
√n+ log(n))
∴|3
√n|> B(4
√n+ log(n)) = B|4
√n+ log(n)|.
Thus there is an integer n > max{(2B)12,216, b} ≥ bsuch that
|3
√n|> B|4
√n+ log(n)|.
This contradicts (1). Hence the supposition is false, and so 3
√nis not O(4
√n+ log(n)).
(b) 100
√nis O(log n)
Solution
No. (2 pts)
Proof (2 pts) Suppose that 100
√nis O(log n). By the supposition that 100
√nis O(log n),
there exists a positive real number Band a real number bsuch that for all integers n > b
|100
√n| ≤ B|log n|(2)
Let B0=max{B, 1}. Let nbe a positive integer that is greater than max{21000B0,b}. Then
We have 100
√n > B0log n≥Blog n.
∴|100
√n|> B|log n|.
Thus there is an integer n > max{(21000B0, b} ≥ bsuch that
|100
√n|> B|log n|.
This contradicts (2). Hence the supposition is false, and so 100
√nis not O(log n).
(c) log3nis O(log n)
Solution
No. (2 pts)
Proof (2 pts) Suppose that log3nis O(log n). By the supposition that log3nis O(log n),
there exists a positive real number Band a real number bsuch that for all integers n > b
|log3n| ≤ |log n|(3)
1
pf3

Partial preview of the text

Download CSE21 Homework Solution: Big O Notation Analysis and more Assignments Computer Science in PDF only on Docsity!

CSE21 HW #3 Solution

  1. (20 Points) Answer whether the followings are true and prove your answer:

(a) 3

n is O( 4

n + log(n))

Solution

No. (2 pts)

Proof (2 pts) Suppose that 3

n is O( 4

n+ log(n)). By the supposition that 3

n is O( 4

n+

log(n)), there exists a positive real number B and a real number b such that for all integers

n > b

| 3

n| ≤ B| 4

n + log(n)| (1)

Let n be a positive integer that is greater than max{(2B) 12 , 16 ,b}. Then

n > (2B) 12 =⇒ | 3

n| = 12

n 4

n > 2 B 4

n 4

n > log(n) for all integers n > 2 16 =⇒ 2 B 4

n > B( 4

n + log(n))

∴ | 3

n| > B( 4

n + log(n)) = B| 4

n + log(n)|.

Thus there is an integer n > max{(2B) 12 , 2 16 , b} ≥ b such that

3

n| > B|

4

n + log(n)|.

This contradicts (1). Hence the supposition is false, and so 3

n is not O( 4

n + log(n)).

(b) 100

n is O(log n)

Solution

No. (2 pts)

Proof (2 pts) Suppose that 100

n is O(log n). By the supposition that 100

n is O(log n),

there exists a positive real number B and a real number b such that for all integers n > b

100

n| ≤ B| log n| (2)

Let B ′ = max{B, 1 }. Let n be a positive integer that is greater than max{ 2 1000 B′ ,b}. Then

We have 100

n > B ′ log n ≥ B log n.

∴ | 100

n| > B| log n|.

Thus there is an integer n > max{( 1000 B′ , b} ≥ b such that

100

n| > B| log n|.

This contradicts (2). Hence the supposition is false, and so 100

n is not O(log n).

(c) log 3 n is O(log n)

Solution

No. (2 pts)

Proof (2 pts) Suppose that log

3 n is O(log n). By the supposition that log

3 n is O(log n),

there exists a positive real number B and a real number b such that for all integers n > b

| log

3 n| ≤ | log n| (3)

Let n be a positive integer that is greater than max{ 2 B

1 2 ,b}. Then

log 3 n = log 2 n log n > B log n.

∴ | log

3 n| > B| log n|.

Thus there is an integer n > b such that

| log

3 n| > B| log n|.

This contradicts (3). Hence the supposition is false, and so log 3 n is not O(log n).

(d) Let a, b be any positive integers.

(a + n) b isO(n a )

Solution

No. (2 pts)

Proof (2 pts) Let a = 1, b = 2. We show (1 + n) 2 is not O(n). This can be proved by

Theorem 9.2.2. Hence, (a + n) b isO(n a ) does not hold for all a, b that are positive integers.

(e) b

nc is O(

n).

Solution

Yes. (2 pts)

Proof (2 pts) For any integer n > 1, |b

nc| = b

nc because since n > 1 > 0, then

b

nc > 0

=⇒ |b

nc| ≤

n because |bxc| ≤ x for all real numbers x

=⇒ b

nc ≤

n because

n ≥ 0.

Let M = 1 and x 0 = 1. Then |b

nc| ≤ M |

n| for all integers n > x 0 , and so by definition

of O-notation, b

nc is O(

n).

  1. (10 Points) A label has the following format: Letter Letter Digit Digit Letter Letter. (Digit

is non-zero and we use capital Letter only.)

(a) (2.5 pts) How many different labels are there?

26 2 × 9 2 × 26 2

(b) (2.5 pts) How many different labels are there with distinct letters and digits?

26 ∗ 25 ∗ 9 ∗ 8 ∗ 24 ∗ 23

(c) (2.5 pts) How many different labels could begin with AB and have non-repeating letters

or digits?

9 ∗ 8 ∗ 24 ∗ 23

(d) (2.5 pts) How many different labels have the letters A and B and have non-repeating

letters or digits?

P (4, 2) ∗ 9 ∗ 8 ∗ 24 ∗ 23 [In the first step we find the positions for A and B (there are P (4, 2)

ways). Then we choose the remaining letters and digits.]

  1. (20 Points) There are 6 students named A,B,C,D,E,F respectively. Now they need to stand in

a line. How many are the different ways to form the line

(a) if A is neither the first nor the last (6th) one.

(b) A and B are either the first or the last (6th) one.