Monday, October 1, 2018

Algorithms Efficiency comparison function

Steps to compare functions 
      Take log on both sides
      Simplify function
      Cancel values if any
      Substitute values of n to see larger function

 Example

          2^n                                                                          n^2 

Take  Log on both sides
          L.H.S                                                       R.H.S
          Log 2^n                                                                 log n^2

          n log 2                                                                   2 log n

                n                                                                         2 log n
 
Put n = 2^100
            2^100                                                                    2 log 2^100

           2^100                                                                     2*100 log 2

         2^100                                                                     200 

So 2^n is larger

No comments:

Post a Comment