22C:044  Homework #4 Solutions

DISPLAYS BETTER WITH INTERNET EXPLORER

page2       page3

 

1.  Order of functions (slowest growth first):

     log(logn), 1000logn, (logn)2, 3n.5, n + cosn, nlog(n2), 100n2 + logn, n3,

     400n – n3 + n5, 2n+1, 3n, 22n, n!

 

    where

      lim 3n/22n  =  lim 3n/4n  = lim (0.75)n = 0

    n®infinity            n®infinity         n®infinity

                          

    and  by L’Hopital’s Rule                                  

       lim (logn)2/(n.5) =  4  lim logn/(n.5)  =  8 lim 1/n.5  =  0

       n®infinity                       n®infinity                        n®infinity                  

                              

2.  Show (n+4)2 = O(n2)   ie find c,n0 > 0  such that  0 <= (n+4)2 <= cn2 for all n >= n0     

          n2 + 8n +16 <= cn2      Try c = 2 (Other choices are also acceptable)

     Then calculate n0

          n02 + 8n0 +16 <= 2n02    ,   any   n0 >=  4(2.5) + 4    will work  for c = 2   

 

3.

a)      Yes. A runs no slower than can2, so it is possible that A always runs at say  1n or faster. B runs at best cbn so B could always run at 2n or slower.

Then A would run faster than B for all inputs.

 

b)      Yes. It could be that A never runs faster than 5nlogn and that B runs at worst

as say 3nlogn. Then B always faster than A. 

 

c)      No. B has a TIGHT upper bound of  nlogn in the worst case, so B will run

as cnlogn for many inputs. C always runs as 2n so there will be  inputs for which B is not faster than C.

 

d)      Yes. B has a lower bound of  n, so B will never run better than cbn. Then it’s

possible B never runs faster than say 3n. But C always runs as 2n, so it’s possible C is always faster than B.

 

e)      Yes. Worst case of  D is W(1). This is a LOOSE lower bound on the worst case

running time, D could be much worse than this in the worst case and could in fact be much worse than this for all inputs. So it could be the case that D is slower

than cn2 for all inputs which would make it slower than A,B,C for all inputs.