Processing math: 100%

Friday, 25 August 2017

Chapter 3 Exercise 3.1-3, Introduction to Algorithms, 3rd Edition Thomas H. Cormen

3.1-3 Explain why the statement, “The running time of algorithm A is at O(n2) ,” is meaningless.

Solution: Let us assume the running time of the algorithm is T(n). Now, by definition, O-notation gives an upper bound for growth of functions but it doesn’t specifies the order of growth. Therefore, saying T(n)O(n2) means growth of T(n) is greater than some upper bound which is meaningless as we do not have any idea about what we are comparing it with.

For example, f(n)=0 is O(n2) for all n. So, T(n)f(n)  doesn’t tell us anything new as all running times are non-negative.

Chapter 3 Exercise 3.1-2, Introduction to Algorithms, 3rd Edition Thomas H. Cormen

3.1-2 Show that for any real constants a and b, where
b>0,(n+a)b=Θ(nb)

Solution:
To prove this, we have to show that there exists constants c1,c2,n0>0 such that 0c1nb(n+a)bc2nb  for all nn0
Note that, n+a2n, when |a|n Also note, n+a12n, when |a|n2 
Therefore, when n2|a|, 0n2n+a2n
As b>0, we can raise all the terms of the previous inequality to the power of b without breaking the inequality:
0(n2)b(n+a)b(2n)b012bnb(n+a)b2bnb
So,(n+a)b=Θ(nb) because there exists c1=1/2b,c2=2b, and  n0=2|a|