You are on page 1of 7

Design & Analysis of Algorithm (CSC-321)

Assignment #1 Solution:

1. Determine 𝐶1 , 𝐶2 and 𝑛0 for the given relations

𝑛2
a) − 3n = Θ(𝑛2 )
2

Solution:

𝑛2
𝐶1 g(n) ≤ − 3n ≤ 𝐶2 g(n)
2

.. . g (n) = 𝑛2 given:

𝑛2
𝐶1 (𝑛2 ) ≤ − 3n ≤ 𝐶2 (𝑛2 )
2

Divide 𝑛2 on the both sides


1 3
𝐶1 ≤ ‾ 𝑛 ≤ 𝐶2
2

For Lower Bound (𝐶1 ):


1 3
𝐶1 ≤ ‾𝑛
2

Let n = 7 𝑛0 ≥ 6
1 3
𝐶1 ≤ ‾7
2

7−6 1
𝐶1 ≤ = 14
14

1
𝐶1 ≤ 14

For Upper Bound (𝐶2 ):

𝑛2
− 3n ≤ 𝐶2 (𝑛2 )
2
As we know

𝑛2 𝑛2
− 3n ≤
2 2

𝑛2 1
− 3n ≤ (𝑛2 )
2 2

1
𝐶2 = 2

b) 3𝑛3 + 6𝑛2 + 6000 = Θ (𝑛3 )

Solution:

𝐶1 (𝑛3 ) ≤ 3𝑛3 + 6𝑛2 + 6000 ≤ 𝐶2 (𝑛3 )

For Lower Bound (𝐶1 ):

3𝑛3 + 6𝑛2 + 6000 ≥ 3𝑛3

Or we can say that

3𝑛3 ≤ 3𝑛3 + 6𝑛2 + 6000

𝐶1 = 3

For 𝑛𝑜 :

6𝑛2 + 6000 ˃ 0

6𝑛2 ˃ - 6000

𝑛2 > - 1000 Negative terms not allowed, neglect negative sign

For Upper Bound (𝐶2 ):

3𝑛3 + 6𝑛2 + 6000 ≤ 3𝑛3 + 6𝑛2 + 6000

3𝑛3 + 6𝑛2 + 6000 ≤ 9𝑛3

For 𝑛0 :
6𝑛2 ≤ 6𝑛3

𝑛0 ≥ 1

2. 6𝑛3 ≠Θ(𝑛2 )

Prove the above relation is true.

Solution:

f (x) = 6𝑛3

g (x) = 𝑛2

Apply Limit Rule:

𝑓(𝑥)
lim =C
𝑛→∞ 𝑔(𝑥)

6𝑛3
lim
𝑛→∞ 𝑛2

lim 6 n
𝑛→∞

Now Applying Limit on both sides:

= 6 (∞)

= ∞

𝑛3 ≠ Θ (𝑛2 ) Proved

3. Suppose program A takes 2n/1000 units of time and program B takes 1000𝑛2 units. For

what values of n does program A take less time than program B?

Solution:
2𝑛
A -> 1000
B -> 1000𝑛2

Program A takes less time


2𝑛
< 1000𝑛2
1000

2𝑛 < 1000000𝑛2

1 < 500000n
1 1
< 500000 or n > 500000 or n > 0.00002 for all values of n
𝑛

4. Following are some big-oh relationships. For each, give witnesses n0 and c that can be

used to prove the relationship. Choose your witnesses to be minimal

a. n2 is O(.001n3)

Solution:

𝑛2 ≤ .001 𝑛3 C=.001

For no:

𝑛2 ≤ .001 𝑛3

𝑛2
≤ .001
𝑛3

1
≤ .001
𝑛

1
𝑛0 ≥ .001 ->Reciprocal

𝑛0 ≥ 1000

b. 25n4 –19n3 + 13n2 – 106n + 77 is O(n4)

Solution:

25n4 –19n3 + 13n2 – 106n + 77 ≤ n4


25n4 + 13n2 + 77 – (19n3 + 106n) ≤ n4

Let consider L.H.S

25n4 + 13n2 + 77 – (19n3 + 106n) ≤ 25n4 + 13n2 + 77 .. . 19n3 + 106n ≥ 0


19n3 ≥ -106n
−106
𝑛2 ≥ 19
n ≥ -2.36 ἰ
25n4 + 13n2 + 77 ≤ 25n4 + 13n4 + 77

≤ 38n4 + 77

≤ 39n4 − 𝑛4 + 77

≤ 39n4 −( 𝑛4 − 77)

≤ 39n4

.. . 𝑛4 − 77 ≥ 0
𝑛4 ≥ 77
𝑛 ≥ 2.96

C =39
no = 2.96

c. 2n+10 is O(2n)

Solution:

2n+10 ≤ C (2n)

2n. 210 ≤ C (2n)

C ≥ 210 for all n

d. n10 is O(3n)

Solution:

n10 ≤ C (3n)

For C:
Apply 𝑙𝑜𝑔𝑛 on both sides

10 ≤ 𝑙𝑜𝑔𝑛 𝐶 + n 𝑙𝑜𝑔𝑛 3

10 ≤ 𝑙𝑜𝑔3 𝐶 + 3 n=3

7 ≤ 𝑙𝑜𝑔3 𝐶

𝑙𝑜𝑔3−1 (7) ≤ C

2187 ≤ C

C ≥ 2187

e. 𝑙𝑜𝑔2 𝑛 is O(√n)

Solution:

𝑙𝑜𝑔2 𝑛 ≤ C √n

Let no = 2

1 ≤ C√2
1
C ≥ √2

5. Suppose that f(n) is O(g(n)) and g(n) is O(f(n)). What can you say about f(n) and g(n)? Is

it necessarily true that f(n) = g(n)? Does the limit f(n)/g(n) as n goes to infinity

necessarily exist?

Solution:

f(n) ≤ Cg(n)

and

g(n) ≤ C f(n)

.. . f (n) = g (n)

Limit Value Exist.


7 Generate a graph for the given values in table 1. And discuss your findings.

You might also like